Skip to content

Commit 46440df

Browse files
committed
[fixed] let jqXHR object survive the fixture copy
1 parent cc6008e commit 46440df

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export var __fixtures__ = {};
5252
*/
5353

5454
export function defineFixture(url, fixture) {
55-
__fixtures__[url] = JSON.parse(JSON.stringify(fixture));
55+
if (fixture.response) {
56+
fixture.response = JSON.parse(JSON.stringify(fixture.response));
57+
}
58+
__fixtures__[url] = fixture;
5659
}
5760

5861
/*

test/main.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ asyncTest('the fixture is unaffected by external change', function() {
9191
)
9292
});
9393

94+
asyncTest('the fixture jqXHR survives the response copy', function() {
95+
96+
ic.ajax.defineFixture('/foo', {
97+
response: {foo: 'bar'},
98+
textStatus: 'success',
99+
jqXHR: { getResponseHeader: function(a) { return a; } }
100+
});
101+
102+
ic.ajax.raw('/foo').then(function(result) {
103+
start();
104+
equal(result.jqXHR.getResponseHeader('foo'), 'foo');
105+
}
106+
)
107+
});
108+
94109
test('throws if success or error callbacks are used', function() {
95110
var k = function() {};
96111
throws(function() {

0 commit comments

Comments
 (0)