javascript - Jasmine/PhantomJS ignoring __defineGetter__ method -
i'm working in tests using jasmine 2.0 , have test code:
describe('my feature test', function () { describe('negative asserts', function () { it('expect location.search not equal pre-defined value', function () { var myqueryvalue = '?custom_query=true'; expect(myqueryvalue).not.toequal(window.location.search); }); }); describe('positive asserts', function () { beforeeach(function () { window.location.__definegetter__('search', function () { return '?custom_query=true'; }); }); it('expect location.search equal pre-defined value', function () { var myqueryvalue = '?custom_query=true'; console.log(window.location.search); expect(myqueryvalue).toequal(window.location.search); }); }); }); i'm using grunt task run code using karma , launching google chrome (karma-chrome-launcher) , phantomjs (karma-phantomjs-launcher) browsers.
in google chrome test pass perfectly
log: '?custom_query=true' chrome 43.0.2357 (mac os x 10.10.3): executed 99 of 99 success (2.889 secs / 2.761 secs) but when test runs in phantomjs __definegetter__ method ignored:
log: '' phantomjs 1.9.8 (mac os x) feature test positive asserts expect location.search equal pre-defined value failed phantomjs 1.9.8 (mac os x): executed 99 of 99 (1 failed) (2.528 secs / 2.522 secs) any ideas why happening?
edit: tried object.defineproperty , still not working.
the defineproperty approach fails in phantomjs following error:
attempting change access mechanism unconfigurable property
i not find place documented, error above makes me wonder if properties not modifiable in phantomjs.
same problem encountered here, suggested solution in case wrap non-overridable methods simple user-defined functions can overridden in tests:
// wrap search property testing purposes function getlocationsearch() { return window.location.search; }
Comments
Post a Comment