jest 学习:模拟 location
解决了 location 的模拟,方便一些关于URL的测试场景
安装
yarn add --dev jest-location-mock
添加文件
- jest.setup.js
- jest.config.js
jest.setup.js
一些 jest的配置,会放在这里
setupFilesAfterEnv: ['./jest.setup.js'],
// https://jestjs.io/docs/en/configuration
module.exports = {
verbose: true,
testRegex: [/\.spec.js/],
//preset: "jest-puppeteer",
automock: false,
setupFilesAfterEnv: ['./jest.setup.js'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
}
};
引入
locatoin.mock
的配置
require('jest-location-mock');
require('jest-location-mock');
jest.setTimeout(60 * 1000);