我有一个小的实用函数,我正在用Jest和酶对我的React-TS项目进行一些测试。在项目中JS文件中,我得到以下错误:
"validateUsername" is read-only.
这是实用程序本身:
export const validateUsername = value =>
listUsers()
.then(({ data }) => {
if (Array.isArray(data) && data.find(userData => userData.username === value)) {
throw 'Username already exists';
}
})
.catch(error => {
throw serverErrorResponseUtil(error);
});
下面是对它的测试:
describe('Validate Username', () => {
const validateUsernameFn = jest.fn();
beforeEach(() => {
validateUsername = validateUsernameFn;
});
it('Should throw an error if the given value exists', async () => {
try {
await validateUsername('username');
} catch (e) {
expect(e).toEqual('Username already exists');
}
});
it('Accept the data if the passed userName is unique', async () => {
expect(() => validateUsername('Username is unique')).not.toThrow();
});
});
我在这里得到了错误:validateUsername = validateUsernameFn;
。问题是这个文件是一个js文件。为什么我得到一个关于只读的ts错误。你们能帮帮我吗?
https://stackoverflow.com/questions/56531551
复制相似问题