-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathunsaved-changes.spec.js
More file actions
36 lines (31 loc) · 1.21 KB
/
unsaved-changes.spec.js
File metadata and controls
36 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sinon from 'sinon';
import createTestContainer from './util/container';
describe('createUnsavedChanges()', () => {
describe('confirm()', () => {
it('returns true if there are no unsaved changes', () => {
const { unsavedChanges } = createTestContainer();
unsavedChanges.confirm().should.be.true;
});
it('prompts the user if there are unsaved changes', () => {
const { unsavedChanges } = createTestContainer();
unsavedChanges.plus(1);
const fake = sinon.fake.returns(true);
sinon.replace(window, 'confirm', fake);
unsavedChanges.confirm();
fake.called.should.be.true;
fake.args[0][0].should.startWith('Are you sure you want to leave this page?');
});
it('returns true if the user confirms', () => {
const { unsavedChanges } = createTestContainer();
unsavedChanges.plus(1);
sinon.replace(window, 'confirm', () => true);
unsavedChanges.confirm().should.be.true;
});
it('returns false if the user does not confirm', () => {
const { unsavedChanges } = createTestContainer();
unsavedChanges.plus(1);
sinon.replace(window, 'confirm', () => false);
unsavedChanges.confirm().should.be.false;
});
});
});