Reputation: 4753
I have a variable declared in html as
<script>
var actionUrl = '@Url.Action(action, "Designer")';
</script>
so that the variable actionUrl can be called in the javascript file I want to test. However, as the unit test isolates each file to test, the actionUrl becomes undefined in karma. How do I mock this variable? What is the best practice?
Upvotes: 4
Views: 10240
Reputation: 4342
window.actionUrl = 'whatever';
unit-tests
|
mocks -
| - module1.js
...
| - moduleN.js
| - globals.js
and then put all global objects in globals.js
and load it inside karma.config.js
Edit: added global mocks to the fork of Angular Seed https://github.com/sbedulin/angular-js-dev-guide
Upvotes: 6