mocking - How do I mock a method in test code that's been "declare"d in production code? -
mocking - How do I mock a method in test code that's been "declare"d in production code? -
in production code, have couple of lines of code that's declaring 2 functions utilize google analytics:
declare function ga(command: string, type: string, exceptiondetails: object); declare function ga(command: string, type: string, category: string, action: string, label: string)
in unit test code, implement mock of these functions nothing. however, app.tests.ts references app.ts, cannot
var ga = (command: string, type: string, exceptiondetails: object) => { };
because duplicate definition.
how can accomplish without adding ga definition unit test runner html?
you override function substituting value. almost doing in example, because have set var
in front end of it, looks accidental duplication.
remove var
, have:
ga = (command: string, type: string, exceptiondetails: object) => { };
simplified illustration illustration:
var ga = (command: string, type: string, exceptiondetails: object) => { alert('hi'); }; // ... ga = (command: string, type: string, exceptiondetails: object) => { alert('overridden'); }; // alerts "overridden" ga('a', 'b', {});
mocking typescript
Comments
Post a Comment