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

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -