Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export function lookupFixture (url) {
return __fixtures__ && __fixtures__[url];
}

/*
* Clears the list of fixtures created by defineFixture()
*/
export function clearFixtures() {
for (var i in __fixtures__) {
if (__fixtures__.hasOwnProperty(i)) {
delete __fixtures__[i];
}
}
}

function makePromise(settings) {
return new Ember.RSVP.Promise(function(resolve, reject) {
var fixture = lookupFixture(settings.url);
Expand Down
14 changes: 14 additions & 0 deletions test/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ asyncTest('the fixture is unaffected by external change', function() {
)
});

test('the fixtures can be cleared', function() {
var response = {foo: 'bar'};

ic.ajax.defineFixture('/foo', {
response: response,
textStatus: 'success',
jqXHR: {}
});

deepEqual(lookupFixture('/foo'), response);
ic.ajax.clearFixtures();
ok(!lookupFixture('/foo'), 'fixture is cleared');
});

test('throws if success or error callbacks are used', function() {
var k = function() {};
throws(function() {
Expand Down