Allow callThrough to call constructor functions without errors
This commit is contained in:
@@ -808,6 +808,25 @@ describe("Env integration", function() {
|
||||
expect(originalFunctionWasCalled).toEqual(true);
|
||||
});
|
||||
|
||||
env.it("works with constructors when using callThrough spy strategy", function() {
|
||||
function MyClass(foo) {
|
||||
if (!(this instanceof MyClass)) throw new Error('You must use the new keyword.');
|
||||
this.foo = foo;
|
||||
}
|
||||
var subject = { MyClass: MyClass };
|
||||
var spy = env.spyOn(subject, 'MyClass').and.callThrough();
|
||||
|
||||
expect(function() {
|
||||
var result = new spy('hello world');
|
||||
expect(result instanceof MyClass).toBeTruthy();
|
||||
expect(result.foo).toEqual('hello world');
|
||||
}).not.toThrow();
|
||||
|
||||
expect(function() {
|
||||
spy('hello world');
|
||||
}).toThrowError('You must use the new keyword.');
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user