How to use the Sinonsandbox.stub
testing framework for rewriting, for example. navigator.language
or navigator.userAgent
for testing?
When I try to use the following:
suite('agent', function () {
var sandbox;
setup(function () {
sandbox = sinon.sandbox.create();
});
teardown(function () {
sandbox.restore();
});
test('language', function () {
assert.equal(au.env.agent.language, navigator.language);
if (!navigator.language) assert.equal(au.env.agent.language, 'de');
var lang = "test_URK";
sandbox.stub(window.navigator, 'language', lang);
assert.equal(au.env.agent.language, lang);
});
});
then I get the following error: You cannot drown out a non-existent native property language :
Without these stubs, they work as expected:
- sandbox.stub (window.navigator, 'language', lang);
- sandbox.stub (navigator, 'browserLanguage', lang);
make fun of the navigator object .
Any clues?