我正在尝试使用 jest 和 vanilla javascript 运行测试用例。
login.test.js
import { validateEmail } from '../assets/js/common';
describe('validate email', () => {
it('should pass with valid email', () => {
const result = validateEmail('example@test.com');
expect(result).toBe(true);
});
it('should fail with invalid email', () => {
const result = validateEmail('exampletest.com');
expect(result).toBe(false);
});
})
common.js
export const validateEmail = (email) => {
return email && EMAIL.test(email);
}
当我跑的时候npm run test
,它在扔
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){
从'../assets/js/common'导入{ validateEmail};
^^^^^^ SyntaxError: Unexpected token import
我在 GitHub 上关注了很多线程,但没有用。他们说的是 React、react-native 以及 Babel 配置等。但我的项目中没有任何.babelrc。它只是 html、css、pug、js 和 webpack。
下面是我的项目目录结构。