Skip to content

Commit 6c63e98

Browse files
fcollonvaltelamonian
authored andcommitted
Fix jest tests
1 parent 35f0e72 commit 6c63e98

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

src/components/diff/mergeview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class DiffView implements MergeView.IDiffView {
256256
private static registerUpdate(dv: DiffView): (mode?: string) => void {
257257
let edit: MergeView.IState = { from: 0, to: 0, marked: [] };
258258
let orig: MergeView.IState = { from: 0, to: 0, marked: [] };
259-
let debounceChange: number;
259+
let debounceChange: ReturnType<typeof setTimeout>;
260260
let updatingFast: boolean = false;
261261

262262
function update(mode?: string) {

tests/test-components/Diff.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Diff', () => {
3030
it('should not render anything when not supported', function() {
3131
// Given
3232
const props: IDiffProps = {
33-
path: '/path/to/File.py',
33+
path: '/path/to/File.unk',
3434
topRepoPath: 'top/repo/path',
3535
diffContext: {
3636
currentRef: { specialRef: 'WORKING' },
@@ -45,7 +45,7 @@ describe('Diff', () => {
4545
expect(node.html()).toBe(null);
4646
});
4747

48-
it('should not support non-ipynb files', function() {
49-
expect(isDiffSupported('/path/to/script.py')).toBeFalsy();
48+
it('should not support non-ipynb and non text files', function() {
49+
expect(isDiffSupported('/path/to/script.unk')).toBeFalsy();
5050
});
5151
});

tests/test-components/NBDiff.spec.tsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as diffResponse from '../test-components/data/diffResponse.json';
1111
jest.mock('../../src/git');
1212

1313
describe('NBDiff', () => {
14-
it('should render error in if API response is failed', async function() {
14+
it('should render error in if API response is failed', async () => {
1515
// Given
1616
const props: IDiffProps = {
1717
path: '/path/to/File.ipynb',
@@ -34,22 +34,22 @@ describe('NBDiff', () => {
3434
const node = shallow(<NBDiff {...props} />);
3535

3636
// Then
37-
jsonResult.then(() => {
38-
node.update();
37+
await jsonResult;
3938

40-
expect(httpGitRequest).toHaveBeenCalled();
41-
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
42-
file_path: '/path/to/File.ipynb',
43-
ref_curr: { special: 'WORKING' },
44-
ref_prev: { git: '83baee' }
45-
});
46-
expect(node.find('.jp-git-diff-error').text()).toContain(
47-
'TEST_ERROR_MESSAGE'
48-
);
39+
node.update();
40+
41+
expect(httpGitRequest).toHaveBeenCalled();
42+
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
43+
file_path: 'top/repo/path/path/to/File.ipynb',
44+
ref_remote: { special: 'WORKING' },
45+
ref_local: { git: '83baee' }
4946
});
47+
expect(node.find('.jp-git-diff-error').text()).toContain(
48+
'TEST_ERROR_MESSAGE'
49+
);
5050
});
5151

52-
it('should render header and cell diff components in success case', async function() {
52+
it('should render header and cell diff components in success case', async () => {
5353
// Given
5454
const props: IDiffProps = {
5555
path: '/path/to/File.ipynb',
@@ -61,7 +61,7 @@ describe('NBDiff', () => {
6161
};
6262

6363
const jsonResult: Promise<any> = Promise.resolve({
64-
diffResponse
64+
...diffResponse
6565
});
6666

6767
(httpGitRequest as jest.Mock).mockReturnValue(
@@ -72,18 +72,17 @@ describe('NBDiff', () => {
7272
const node = shallow(<NBDiff {...props} />);
7373

7474
// Then
75-
jsonResult.then(() => {
76-
node.update();
75+
await jsonResult;
76+
node.update();
7777

78-
expect(httpGitRequest).toHaveBeenCalled();
79-
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
80-
file_path: '/path/to/File.ipynb',
81-
ref_curr: { special: 'WORKING' },
82-
ref_prev: { git: '83baee' }
83-
});
84-
expect(node.find('.jp-git-diff-error').html()).toBeNull();
85-
expect(node.find(NBDiffHeader)).toHaveLength(1);
86-
expect(node.find(CellDiff)).toHaveLength(2);
78+
expect(httpGitRequest).toHaveBeenCalled();
79+
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
80+
file_path: 'top/repo/path/path/to/File.ipynb',
81+
ref_remote: { special: 'WORKING' },
82+
ref_local: { git: '83baee' }
8783
});
84+
expect(node.find('.jp-git-diff-error')).toHaveLength(0);
85+
expect(node.find(NBDiffHeader)).toHaveLength(1);
86+
expect(node.find(CellDiff)).toHaveLength(3);
8887
});
8988
});

0 commit comments

Comments
 (0)