-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathnotes.spec.js
More file actions
117 lines (90 loc) · 2.7 KB
/
notes.spec.js
File metadata and controls
117 lines (90 loc) · 2.7 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
describe("App.Collections.Notes", function () {
before(function () {
// Create a reference for all internal suites/specs.
this.notes = new App.Collections.Notes();
// Use internal method to clear out existing data.
this.notes.localStorage._clear();
});
after(function () {
// Remove the reference.
this.notes = null;
});
describe("creation", function () {
it("has default values", function () {
expect(this.notes).to.be.ok;
expect(this.notes).to.have.length(0);
});
// -- Omitted in Book. --
it("should be empty on fetch", function (done) {
// Stash reference to save context.
var notes = this.notes;
// Before fetch.
expect(notes).to.be.ok;
expect(notes).to.have.length(0);
// After fetch.
notes.once("reset", function () {
expect(notes).to.have.length(0);
done();
});
notes.fetch({ reset: true });
});
});
describe("modification", function () {
beforeEach(function () {
// Load a pre-existing note.
this.notes.create({
title: "Test note #1",
text: "A pre-existing note from beforeEach."
});
});
afterEach(function () {
// Wipe internal data and reset collection.
this.notes.localStorage._clear();
this.notes.reset();
});
it("has a single note", function (done) {
var notes = this.notes, note;
// After fetch.
notes.once("reset", function () {
expect(notes).to.have.length(1);
// Check model attributes.
note = notes.at(0);
expect(note).to.be.ok;
expect(note.get("title")).to.contain("#1");
expect(note.get("text")).to.contain("pre-existing");
done();
});
notes.fetch({ reset: true });
});
it("can delete a note", function (done) {
var notes = this.notes, note;
// After shift.
notes.once("remove", function () {
expect(notes).to.have.length(0);
done();
});
// Remove and return first model.
note = notes.shift();
expect(note).to.be.ok;
});
// -- Omitted in Book. --
it("can create a second note", function (done) {
var notes = this.notes,
note = notes.create({
title: "Test note #2",
text: "A new note, created in the test."
});
// After fetch.
notes.once("reset", function () {
expect(notes).to.have.length(2);
// Check model attributes.
note = notes.at(1);
expect(note).to.be.ok;
expect(note.get("title")).to.contain("#2");
expect(note.get("text")).to.contain("new note");
done();
});
notes.fetch({ reset: true });
});
});
});