- Mock imported modules when using karma-typescript
npm install --save-dev karma-typescript-mock
import { KarmaTypescriptMocker } from "karma-typescript-mock";
var KarmaTypescriptMocker = new KarmaTypescriptMocker();
let restore = KarmaTypescriptMocker.mock('qs', { parse: ()=>()=>"result"})
restore();
- mock
- mockExport
- restoreAll
- When passing in a function then it must be wrapped in another function e.g. ()=>{ spy = x; return mockFunc}
import { JasmineKarmaTypeScriptMocker } from "karma-typescript-mock-jasmine";
describe('Test', ()=>{
JasmineKarmaTypeScriptMocker('qs', { parse: ()=>()=>"result})
it('it', ()=>{
})
})
import { JasmineKarmaTypeScriptMockerSingle } from "karma-typescript-mock-jasmine";
describe('Test', ()=>{
JasmineKarmaTypeScriptMockerSingle('qs', parse', ()=>()=>"result)
it('it', ()=>{
})
})
- KarmaTypescriptMocker.mock('C:/projects/karma-typescript-mock/src/bar.ts'
- KarmaTypescriptMocker.mock('src/bar.ts'
- KarmaTypescriptMocker.mock('src/bar.ts'
- KarmaTypescriptMocker.mock('src/bar'
- KarmaTypescriptMocker.mock('./src/bar.ts'
- KarmaTypescriptMocker.mock('./src/bar'
- KarmaTypescriptMocker.mock('./bar.ts'
- KarmaTypescriptMocker.mock('./bar
- KarmaTypescriptMocker.mock('query-string'
- KarmaTypescriptMocker.mock('@private/custom'
- cannot mock exported primitive values like strings
- cannot mock if import is a function e.g. cookies-js
- cannot mock if import is executed immedidately