Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 320956a

Browse files
authored
Merge pull request #10 from withspectrum/fix-tests
Fix tests
2 parents 1da25f1 + fa9a66b commit 320956a

File tree

6 files changed

+51
-54
lines changed

6 files changed

+51
-54
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testRegex: "(/__tests__/.*|(\\.|/|-)(test|spec))\\.jsx?$",
3+
};

src/modifiers/__test__/handleImage-test.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sinon from "sinon";
2-
import { expect } from "chai";
31
import Draft, { EditorState, SelectionState } from "draft-js";
42
import handleImage from "../handleImage";
53

@@ -9,7 +7,7 @@ describe("handleImage", () => {
97
let selection;
108
let fakeInsertImage;
119

12-
after(() => {
10+
afterAll(() => {
1311
handleImage.__ResetDependency__("insertImage"); // eslint-disable-line no-underscore-dangle
1412
});
1513

@@ -65,7 +63,7 @@ describe("handleImage", () => {
6563
"insert-image"
6664
);
6765

68-
fakeInsertImage = sinon.spy(() => newEditorState);
66+
fakeInsertImage = jest.fn(() => newEditorState);
6967

7068
handleImage.__Rewire__("insertImage", fakeInsertImage); // eslint-disable-line no-underscore-dangle
7169

@@ -90,20 +88,20 @@ describe("handleImage", () => {
9088
it("returns new editor state", () => {
9189
const editorState = createEditorState(text);
9290
const newEditorState = handleImage(editorState, " ");
93-
expect(newEditorState).not.to.equal(editorState);
94-
expect(
95-
Draft.convertToRaw(newEditorState.getCurrentContent())
96-
).to.deep.equal(afterRawContentState);
97-
expect(fakeInsertImage).to.have.callCount(1);
91+
expect(newEditorState).not.toEqual(editorState);
92+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
93+
afterRawContentState
94+
);
95+
expect(fakeInsertImage).toHaveBeenCalledTimes(1);
9896
});
9997
});
10098
});
10199
describe("if does not match", () => {
102100
it("returns old editor state", () => {
103101
const editorState = createEditorState("yo");
104102
const newEditorState = handleImage(editorState, " ");
105-
expect(newEditorState).to.equal(editorState);
106-
expect(fakeInsertImage).not.to.have.been.called();
103+
expect(newEditorState).toEqual(editorState);
104+
expect(fakeInsertImage).not.toHaveBeenCalled();
107105
});
108106
});
109107
});

src/modifiers/__test__/handleLink-test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sinon from "sinon";
2-
import { expect } from "chai";
32
import Draft, { EditorState, SelectionState } from "draft-js";
43
import handleLink from "../handleLink";
54

@@ -9,7 +8,7 @@ describe("handleLink", () => {
98
let selection;
109
let fakeInsertLink;
1110

12-
after(() => {
11+
afterAll(() => {
1312
handleLink.__ResetDependency__("../insertLink"); // eslint-disable-line no-underscore-dangle
1413
});
1514

@@ -65,7 +64,7 @@ describe("handleLink", () => {
6564
"insert-image"
6665
);
6766

68-
fakeInsertLink = sinon.spy(() => newEditorState);
67+
fakeInsertLink = jest.fn(() => newEditorState);
6968

7069
handleLink.__Rewire__("insertLink", fakeInsertLink); // eslint-disable-line no-underscore-dangle
7170

@@ -80,20 +79,20 @@ describe("handleLink", () => {
8079
it("returns new editor state", () => {
8180
const editorState = createEditorState(text);
8281
const newEditorState = handleLink(editorState, " ");
83-
expect(newEditorState).not.to.equal(editorState);
84-
expect(
85-
Draft.convertToRaw(newEditorState.getCurrentContent())
86-
).to.deep.equal(afterRawContentState);
87-
expect(fakeInsertLink).to.have.callCount(1);
82+
expect(newEditorState).not.toEqual(editorState);
83+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
84+
afterRawContentState
85+
);
86+
expect(fakeInsertLink).toHaveBeenCalledTimes(1);
8887
});
8988
});
9089
});
9190
describe("if does not match", () => {
9291
it("returns old editor state", () => {
9392
const editorState = createEditorState("yo");
9493
const newEditorState = handleLink(editorState, " ");
95-
expect(newEditorState).to.equal(editorState);
96-
expect(fakeInsertLink).not.to.have.been.called();
94+
expect(newEditorState).toEqual(editorState);
95+
expect(fakeInsertLink).not.toHaveBeenCalled();
9796
});
9897
});
9998
});

src/modifiers/__test__/handleNewCodeBlock-test.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { expect } from "chai";
21
import sinon from "sinon";
32
import Draft, { EditorState, SelectionState } from "draft-js";
43
import handleNewCodeBlock from "../handleNewCodeBlock";
@@ -49,10 +48,10 @@ describe("handleNewCodeBlock", () => {
4948
);
5049
it("creates new code block", () => {
5150
const newEditorState = handleNewCodeBlock(editorState);
52-
expect(newEditorState).not.to.equal(editorState);
53-
expect(
54-
Draft.convertToRaw(newEditorState.getCurrentContent())
55-
).to.deep.equal(afterRawContentState);
51+
expect(newEditorState).not.toEqual(editorState);
52+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
53+
afterRawContentState
54+
);
5655
});
5756
};
5857

@@ -61,10 +60,10 @@ describe("handleNewCodeBlock", () => {
6160
});
6261

6362
describe("in code block", () => {
64-
before(() => {
63+
beforeAll(() => {
6564
sinon.stub(Draft, "genKey").returns("item2");
6665
});
67-
after(() => {
66+
afterAll(() => {
6867
Draft.genKey.restore();
6968
});
7069
const beforeRawContentState = {
@@ -119,10 +118,10 @@ describe("handleNewCodeBlock", () => {
119118
selection
120119
);
121120
const newEditorState = handleNewCodeBlock(editorState);
122-
expect(newEditorState).not.to.equal(editorState);
123-
expect(
124-
Draft.convertToRaw(newEditorState.getCurrentContent())
125-
).to.deep.equal(afterRawContentState);
121+
expect(newEditorState).not.toEqual(editorState);
122+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
123+
afterRawContentState
124+
);
126125
});
127126
it("does not add new line even inside code block", () => {
128127
const selection = new SelectionState({
@@ -138,10 +137,10 @@ describe("handleNewCodeBlock", () => {
138137
selection
139138
);
140139
const newEditorState = handleNewCodeBlock(editorState);
141-
expect(newEditorState).to.equal(editorState);
142-
expect(
143-
Draft.convertToRaw(newEditorState.getCurrentContent())
144-
).to.deep.equal(beforeRawContentState);
140+
expect(newEditorState).toEqual(editorState);
141+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
142+
beforeRawContentState
143+
);
145144
});
146145
});
147146

@@ -175,10 +174,10 @@ describe("handleNewCodeBlock", () => {
175174
);
176175
it("noop", () => {
177176
const newEditorState = handleNewCodeBlock(editorState);
178-
expect(newEditorState).to.equal(editorState);
179-
expect(
180-
Draft.convertToRaw(newEditorState.getCurrentContent())
181-
).to.deep.equal(rawContentState);
177+
expect(newEditorState).toEqual(editorState);
178+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
179+
rawContentState
180+
);
182181
});
183182
});
184183
});

src/modifiers/__test__/insertEmptyBlock-test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { expect } from "chai";
21
import sinon from "sinon";
32
import Draft, { EditorState, SelectionState } from "draft-js";
43
import insertEmptyBlock from "../insertEmptyBlock";
54

65
describe("insertEmptyBlock", () => {
7-
before(() => {
6+
beforeAll(() => {
87
sinon.stub(Draft, "genKey").returns("item2");
98
});
10-
after(() => {
9+
afterAll(() => {
1110
Draft.genKey.restore();
1211
});
1312
const testInsertEmptyBlock = (...args) => () => {
@@ -62,10 +61,10 @@ describe("insertEmptyBlock", () => {
6261

6362
it("creates new code block", () => {
6463
const newEditorState = insertEmptyBlock(editorState, ...args);
65-
expect(newEditorState).not.to.equal(editorState);
66-
expect(
67-
Draft.convertToRaw(newEditorState.getCurrentContent())
68-
).to.deep.equal(afterRawContentState);
64+
expect(newEditorState).not.toEqual(editorState);
65+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
66+
afterRawContentState
67+
);
6968
});
7069
};
7170

src/modifiers/__test__/leaveList-test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { expect } from "chai";
21
import sinon from "sinon";
32
import Draft, { EditorState, SelectionState } from "draft-js";
43
import leaveList from "../leaveList";
54

65
describe("leaveList", () => {
7-
before(() => {
6+
beforeAll(() => {
87
sinon.stub(Draft, "genKey").returns("item2");
98
});
10-
after(() => {
9+
afterAll(() => {
1110
Draft.genKey.restore();
1211
});
1312
[
@@ -58,10 +57,10 @@ describe("leaveList", () => {
5857
);
5958
it("converts block type", () => {
6059
const newEditorState = leaveList(editorState);
61-
expect(newEditorState).not.to.equal(editorState);
62-
expect(
63-
Draft.convertToRaw(newEditorState.getCurrentContent())
64-
).to.deep.equal(afterRawContentState);
60+
expect(newEditorState).not.toEqual(editorState);
61+
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
62+
afterRawContentState
63+
);
6564
});
6665
});
6766
});

0 commit comments

Comments
 (0)