Skip to content

Commit 2c65eae

Browse files
committed
chore: 🤖 migrate tests to new Jest version
1 parent ca0fa69 commit 2c65eae

File tree

9 files changed

+7545
-8261
lines changed

9 files changed

+7545
-8261
lines changed

package-lock.json

Lines changed: 7422 additions & 8177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@
4444
"@semantic-release/git": "^7.0.17",
4545
"@types/jasmine": "~3.6.0",
4646
"@types/jasminewd2": "~2.0.3",
47-
"@types/jest": "^24.0.19",
47+
"@types/jest": "^27.0.3",
4848
"@types/node": "^12.11.1",
4949
"codecov": "^3.6.1",
5050
"codelyzer": "^6.0.0",
5151
"copyfiles": "^2.1.1",
5252
"husky": "^3.0.9",
5353
"jasmine-core": "~3.6.0",
5454
"jasmine-spec-reporter": "~5.0.0",
55-
"jest": "^24.9.0",
56-
"jest-preset-angular": "^8.1.3",
55+
"jest": "^27.4.5",
56+
"jest-preset-angular": "^11.0.1",
5757
"ng-packagr": "^13.1.1",
5858
"npm-run-all": "^4.1.5",
5959
"prettier": "^1.18.2",
6060
"pretty-quick": "^2.0.0",
6161
"protractor": "~7.0.0",
6262
"replace-json-property": "^1.4.1",
6363
"semantic-release": "^15.13.30",
64-
"ts-jest": "^24.1.0",
64+
"ts-jest": "^27.1.1",
6565
"ts-node": "~7.0.0",
6666
"tslint": "~6.1.0",
6767
"typescript": "~4.5.4"

projects/pretty-html-log/src/lib/logNgHTML.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('LogNgHTML', () => {
4949
});
5050

5151
it('should call prettyPrintFixture incase we provide a component fixture', () => {
52-
spyOn(fixturePrettier, 'fixturePrettier');
52+
jest.spyOn(fixturePrettier, 'fixturePrettier');
5353
logNgHTML<MockComponent>(fixture, enableComments, theme);
5454
expect(fixturePrettier.fixturePrettier).toHaveBeenCalledWith(
5555
fixture,
@@ -59,8 +59,8 @@ describe('LogNgHTML', () => {
5959
});
6060

6161
it('should call prettyPrintDebugElements in case we provide an array of DebugElements', () => {
62-
spyOn(console, 'log');
63-
spyOn(debugElementPrettier, 'prettyPrintDebugElements');
62+
jest.spyOn(console, 'log');
63+
jest.spyOn(debugElementPrettier, 'prettyPrintDebugElements');
6464
const debugElements = fixture.debugElement.queryAll(By.css('li'));
6565
logNgHTML(debugElements, enableComments, theme);
6666
expect(debugElementPrettier.prettyPrintDebugElements).toHaveBeenCalledWith(
@@ -71,8 +71,8 @@ describe('LogNgHTML', () => {
7171
});
7272

7373
it('should call prettyPrintHTMLElements in case we provide an array of HTMLelements', () => {
74-
spyOn(console, 'log');
75-
spyOn(htmlElementPrettier, 'prettyPrintHtmlElements');
74+
jest.spyOn(console, 'log');
75+
jest.spyOn(htmlElementPrettier, 'prettyPrintHtmlElements');
7676
const htmlElements = fixture.debugElement
7777
.queryAll(By.css('li'))
7878
.map((debugElement: DebugElement) => debugElement.nativeElement);
@@ -85,7 +85,7 @@ describe('LogNgHTML', () => {
8585
});
8686

8787
it('should call prettyPrintDebugElement in case we provide a debug element', () => {
88-
spyOn(debugElementPrettier, 'prettyPrintDebugElement');
88+
jest.spyOn(debugElementPrettier, 'prettyPrintDebugElement');
8989
const debugElement = fixture.debugElement.queryAll(By.css('li'))[0];
9090
logNgHTML(debugElement, enableComments, theme);
9191
expect(debugElementPrettier.prettyPrintDebugElement).toHaveBeenCalledWith(
@@ -96,7 +96,7 @@ describe('LogNgHTML', () => {
9696
});
9797

9898
it('should call prettyPrintHTMLElement in case we provide a HTMLelement', () => {
99-
spyOn(htmlElementPrettier, 'prettyPrintHtmlElement');
99+
jest.spyOn(htmlElementPrettier, 'prettyPrintHtmlElement');
100100
const htmlElement = fixture.debugElement.queryAll(By.css('li'))[0]
101101
.nativeElement;
102102
logNgHTML(htmlElement, enableComments, theme);
@@ -108,8 +108,8 @@ describe('LogNgHTML', () => {
108108
});
109109

110110
it('should print a warning if we pass in an unknown type', () => {
111-
spyOn(console, 'log');
112-
spyOn(prettyHTMLLog, 'highlight');
111+
jest.spyOn(console, 'log');
112+
jest.spyOn(prettyHTMLLog, 'highlight');
113113
const htmlString = '<h1>Foo</h1>';
114114
logNgHTML(htmlString, enableComments, theme);
115115
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(htmlString, theme);
@@ -118,11 +118,11 @@ describe('LogNgHTML', () => {
118118
it('should print a warning and remove the comments we pass in an unknown type and enableComments', () => {
119119
const htmlString = '<h1>Foo</h1><!--Some comment-->';
120120
const commentFreeHTMLString = '<h1>Foo</h1>';
121-
spyOn(console, 'log');
122-
spyOn(prettyHTMLLog, 'highlight');
123-
spyOn(prettierUtil, 'removeComments').and.returnValue(
124-
commentFreeHTMLString
125-
);
121+
jest.spyOn(console, 'log');
122+
jest.spyOn(prettyHTMLLog, 'highlight');
123+
jest
124+
.spyOn(prettierUtil, 'removeComments')
125+
.mockReturnValue(commentFreeHTMLString);
126126
logNgHTML(htmlString, false, theme);
127127
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(
128128
commentFreeHTMLString,
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
describe('Patch console', () => {
2-
it('should not contain a console.logNgHTML method', () => {
3-
expect((console as any).logNgHTML).not.toBeDefined();
4-
});
5-
6-
it('should patch the console and add a console.logNgHTML method', () => {
1+
describe('Add global', () => {
2+
it('should add a logNgHTML method to the global', () => {
3+
expect((global as any).logNgHTML).not.toBeDefined();
74
require('./patchConsole');
8-
expect((console as any).logNgHTML).toBeDefined();
5+
expect((global as any).logNgHTML).toBeDefined();
96
});
107
});

projects/pretty-html-log/src/lib/patchConsole.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

projects/pretty-html-log/src/lib/prettiers/debugElement/pretty-debugElement.spec.ts

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ import { prettyPrintDebugElement } from './pretty-debugElement';
1010
describe('pretty debug element', () => {
1111
it('should call prettyDebugelement with the debugElement and pass it to console.log', () => {
1212
console.log = jest.fn();
13-
const debugElement = {} as DebugElement;
14-
spyOn(debugElementPrettier, 'prettyDebugelement');
13+
const debugElement = {
14+
nativeElement: {
15+
innerHTML: '<h1>Mock element</h1>'
16+
}
17+
} as DebugElement;
18+
jest.spyOn(debugElementPrettier, 'prettyDebugelement');
1519
debugElementPrettier.prettyPrintDebugElement(
1620
debugElement,
1721
true,
1822
THEMES.DRACULA
1923
);
2024

21-
expect(console.log).toHaveBeenCalledWith(
22-
prettyPrintDebugElement(debugElement, true, THEMES.DRACULA)
25+
expect(console.log).toHaveBeenCalled();
26+
expect(debugElementPrettier.prettyDebugelement).toHaveBeenCalledWith(
27+
debugElement,
28+
true,
29+
THEMES.DRACULA
2330
);
2431
});
2532

@@ -28,30 +35,52 @@ describe('pretty debug element', () => {
2835
for each `, () => {
2936
console.log = jest.fn();
3037

31-
const debugElementOne = { name: 'DebugElementOne' } as DebugElement;
32-
const debugElementTwo = { name: 'DebugElementTwo' } as DebugElement;
33-
const debugElementThree = { name: 'DebugElementThree' } as DebugElement;
38+
const debugElementOne = {
39+
name: 'DebugElementOne',
40+
nativeElement: {
41+
innerHTML: '<h1>first mock element</h1>'
42+
}
43+
} as DebugElement;
44+
const debugElementTwo = {
45+
name: 'DebugElementTwo',
46+
nativeElement: {
47+
innerHTML: '<h1>second mock element</h1>'
48+
}
49+
} as DebugElement;
50+
const debugElementThree = {
51+
name: 'DebugElementThree',
52+
nativeElement: {
53+
innerHTML: '<h1>third mock element</h1>'
54+
}
55+
} as DebugElement;
3456

3557
const debugElements = [
3658
debugElementOne,
3759
debugElementTwo,
3860
debugElementThree
3961
] as DebugElement[];
40-
spyOn(debugElementPrettier, 'prettyDebugelement');
62+
jest.spyOn(debugElementPrettier, 'prettyDebugelement');
4163
debugElementPrettier.prettyPrintDebugElements(
4264
debugElements,
4365
true,
4466
THEMES.DRACULA
4567
);
4668

47-
expect(console.log).toHaveBeenCalledWith(
48-
prettyPrintDebugElement(debugElementOne, true, THEMES.DRACULA)
69+
expect(console.log).toHaveBeenCalledTimes(3);
70+
expect(debugElementPrettier.prettyDebugelement).toHaveBeenCalledWith(
71+
debugElementOne,
72+
true,
73+
THEMES.DRACULA
4974
);
50-
expect(console.log).toHaveBeenCalledWith(
51-
prettyPrintDebugElement(debugElementTwo, true, THEMES.DRACULA)
75+
expect(debugElementPrettier.prettyDebugelement).toHaveBeenCalledWith(
76+
debugElementTwo,
77+
true,
78+
THEMES.DRACULA
5279
);
53-
expect(console.log).toHaveBeenCalledWith(
54-
prettyPrintDebugElement(debugElementThree, true, THEMES.DRACULA)
80+
expect(debugElementPrettier.prettyDebugelement).toHaveBeenCalledWith(
81+
debugElementThree,
82+
true,
83+
THEMES.DRACULA
5584
);
5685
});
5786

@@ -62,7 +91,7 @@ describe('pretty debug element', () => {
6291
innerHTML
6392
}
6493
} as DebugElement;
65-
spyOn(prettyHTMLLog, 'highlight');
94+
jest.spyOn(prettyHTMLLog, 'highlight');
6695

6796
debugElementPrettier.prettyDebugelement(debugElement, true, THEMES.DRACULA);
6897
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(
@@ -79,8 +108,8 @@ describe('pretty debug element', () => {
79108
innerHTML
80109
}
81110
} as DebugElement;
82-
spyOn(prettyHTMLLog, 'highlight');
83-
spyOn(prettierUtil, 'removeComments').and.returnValue(commentFreeHTML);
111+
jest.spyOn(prettyHTMLLog, 'highlight');
112+
jest.spyOn(prettierUtil, 'removeComments').mockReturnValue(commentFreeHTML);
84113

85114
debugElementPrettier.prettyDebugelement(
86115
debugElement,

projects/pretty-html-log/src/lib/prettiers/fixture/pretty-fixture.spec.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ import { fixturePrettier } from './pretty-fixture';
1010
describe('pretty fixture', () => {
1111
it('should call prettyFixture with the componentFixture and pass it to console.log', () => {
1212
console.log = jest.fn();
13-
const componentFixture = {} as ComponentFixture<any>;
14-
spyOn(prettyFixture, 'prettyFixture');
13+
const componentFixture = {
14+
debugElement: {
15+
nativeElement: {
16+
innerHTML: '<h1>some mock element</h1>'
17+
}
18+
}
19+
} as ComponentFixture<any>;
20+
jest.spyOn(prettyFixture, 'prettyFixture');
1521
prettyFixture.fixturePrettier(componentFixture, false, THEMES.DRACULA);
1622

17-
expect(console.log).toHaveBeenCalledWith(
18-
fixturePrettier(componentFixture, false, THEMES.DRACULA)
23+
expect(console.log).toHaveBeenCalled();
24+
expect(prettyFixture.prettyFixture).toHaveBeenCalledWith(
25+
componentFixture,
26+
false,
27+
THEMES.DRACULA
1928
);
2029
});
2130

@@ -28,7 +37,7 @@ describe('pretty fixture', () => {
2837
}
2938
}
3039
} as ComponentFixture<any>;
31-
spyOn(prettyHTMLLog, 'highlight');
40+
jest.spyOn(prettyHTMLLog, 'highlight');
3241

3342
prettyFixture.prettyFixture(componentFixture, true, THEMES.DRACULA);
3443
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(
@@ -47,8 +56,8 @@ describe('pretty fixture', () => {
4756
}
4857
}
4958
} as ComponentFixture<any>;
50-
spyOn(prettyHTMLLog, 'highlight');
51-
spyOn(prettierUtil, 'removeComments').and.returnValue(commentFreeHTML);
59+
jest.spyOn(prettyHTMLLog, 'highlight');
60+
jest.spyOn(prettierUtil, 'removeComments').mockReturnValue(commentFreeHTML);
5261

5362
prettyFixture.prettyFixture(componentFixture, false, THEMES.DRACULA);
5463
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(

projects/pretty-html-log/src/lib/prettiers/htmlElement/pretty-htmlelement.spec.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ import { prettyPrintHtmlElement } from './pretty-htmlelement';
99
describe('pretty HTML element', () => {
1010
it('should call prettyHtmlElement with the htmlElement and pass it to console.log', () => {
1111
console.log = jest.fn();
12-
const htmlElement = {} as HTMLElement;
13-
spyOn(htmlElementPrettier, 'prettyHtmlElement');
12+
const htmlElement = {
13+
innerHTML: '<h1>Some mock</h1>'
14+
} as HTMLElement;
15+
jest.spyOn(htmlElementPrettier, 'prettyHtmlElement');
1416
htmlElementPrettier.prettyPrintHtmlElement(
1517
htmlElement,
1618
false,
1719
THEMES.DRACULA
1820
);
1921

20-
expect(console.log).toHaveBeenCalledWith(
21-
prettyPrintHtmlElement(htmlElement, false, THEMES.DRACULA)
22+
expect(console.log).toHaveBeenCalled();
23+
expect(htmlElementPrettier.prettyHtmlElement).toHaveBeenCalledWith(
24+
htmlElement,
25+
false,
26+
THEMES.DRACULA
2227
);
2328
});
2429

@@ -27,30 +32,46 @@ describe('pretty HTML element', () => {
2732
for each `, () => {
2833
console.log = jest.fn();
2934

30-
const htmlElementOne = { innerText: 'HtmlElementOne' } as HTMLElement;
31-
const htmlElementTwo = { innerText: 'HtmlElementTwo' } as HTMLElement;
32-
const htmlElementThree = { innerText: 'HtmlElementThree' } as HTMLElement;
35+
const htmlElementOne = {
36+
innerHTML: '<h1>first mock element</h1>',
37+
innerText: 'HtmlElementOne'
38+
} as HTMLElement;
39+
const htmlElementTwo = {
40+
innerHTML: '<h1>second mock element</h1>',
41+
innerText: 'HtmlElementTwo'
42+
} as HTMLElement;
43+
const htmlElementThree = {
44+
innerHTML: '<h1>third mock element</h1>',
45+
innerText: 'HtmlElementThree'
46+
} as HTMLElement;
3347

3448
const htmlElements = [
3549
htmlElementOne,
3650
htmlElementTwo,
3751
htmlElementThree
3852
] as HTMLElement[];
39-
spyOn(htmlElementPrettier, 'prettyHtmlElement');
53+
jest.spyOn(htmlElementPrettier, 'prettyHtmlElement');
4054
htmlElementPrettier.prettyPrintHtmlElements(
4155
htmlElements,
4256
false,
4357
THEMES.DRACULA
4458
);
4559

46-
expect(console.log).toHaveBeenCalledWith(
47-
prettyPrintHtmlElement(htmlElementOne, false, THEMES.DRACULA)
60+
expect(console.log).toHaveBeenCalledTimes(3);
61+
expect(htmlElementPrettier.prettyHtmlElement).toHaveBeenCalledWith(
62+
htmlElementOne,
63+
false,
64+
THEMES.DRACULA
4865
);
49-
expect(console.log).toHaveBeenCalledWith(
50-
prettyPrintHtmlElement(htmlElementTwo, false, THEMES.DRACULA)
66+
expect(htmlElementPrettier.prettyHtmlElement).toHaveBeenCalledWith(
67+
htmlElementTwo,
68+
false,
69+
THEMES.DRACULA
5170
);
52-
expect(console.log).toHaveBeenCalledWith(
53-
prettyPrintHtmlElement(htmlElementThree, false, THEMES.DRACULA)
71+
expect(htmlElementPrettier.prettyHtmlElement).toHaveBeenCalledWith(
72+
htmlElementThree,
73+
false,
74+
THEMES.DRACULA
5475
);
5576
});
5677

@@ -59,7 +80,7 @@ describe('pretty HTML element', () => {
5980
const htmlElement = {
6081
innerHTML
6182
} as HTMLElement;
62-
spyOn(prettyHTMLLog, 'highlight');
83+
jest.spyOn(prettyHTMLLog, 'highlight');
6384

6485
htmlElementPrettier.prettyHtmlElement(htmlElement, true, THEMES.DRACULA);
6586
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(
@@ -74,8 +95,8 @@ describe('pretty HTML element', () => {
7495
const htmlElement = {
7596
innerHTML
7697
} as HTMLElement;
77-
spyOn(prettyHTMLLog, 'highlight');
78-
spyOn(prettierUtil, 'removeComments').and.returnValue(commentFreeHTML);
98+
jest.spyOn(prettyHTMLLog, 'highlight');
99+
jest.spyOn(prettierUtil, 'removeComments').mockReturnValue(commentFreeHTML);
79100

80101
htmlElementPrettier.prettyHtmlElement(htmlElement, false, THEMES.DRACULA);
81102
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)