Skip to content

Commit 757753f

Browse files
committed
fixed unit tests
1 parent 7d32647 commit 757753f

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/builds/builds.service.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { PrismaService } from '../prisma/prisma.service';
44
import { TestRunsService } from '../test-runs/test-runs.service';
55
import { EventsGateway } from '../shared/events/events.gateway';
66
import { Build, TestRun, TestStatus } from '@prisma/client';
7-
import { mocked } from 'ts-jest/utils';
87
import { BuildDto } from './dto/build.dto';
98
import { ProjectsService } from '../projects/projects.service';
109
import { generateTestRun } from '../_data_';
@@ -115,20 +114,20 @@ describe('BuildsService', () => {
115114
it('findOne', async () => {
116115
const buildFindUniqueMock = jest.fn().mockResolvedValueOnce(build);
117116
const testRunFindManyMock = jest.fn().mockResolvedValueOnce(build.testRuns);
118-
mocked(BuildDto).mockReturnValueOnce(buildDto);
117+
jest.mocked(BuildDto).mockReturnValueOnce(buildDto);
119118
service = await initService({ buildFindUniqueMock, testRunFindManyMock });
120119

121120
const result = await service.findOne('someId');
122121

123-
expect(mocked(BuildDto)).toHaveBeenCalledWith({ ...build, testRuns: build.testRuns });
122+
expect(jest.mocked(BuildDto)).toHaveBeenCalledWith({ ...build, testRuns: build.testRuns });
124123
expect(result).toBe(buildDto);
125124
});
126125

127126
it('findMany', async () => {
128127
const buildFindManyMock = jest.fn().mockResolvedValueOnce([build]);
129128
const buildCountMock = jest.fn().mockResolvedValueOnce(33);
130129
const projectId = 'someId';
131-
mocked(BuildDto).mockReturnValueOnce(buildDto);
130+
jest.mocked(BuildDto).mockReturnValueOnce(buildDto);
132131
service = await initService({ buildFindManyMock, buildCountMock });
133132

134133
const result = await service.findMany(projectId, 10, 20);
@@ -183,7 +182,7 @@ describe('BuildsService', () => {
183182
const id = 'some id';
184183
const buildUpdateMock = jest.fn();
185184
const eventsBuildUpdatedMock = jest.fn();
186-
mocked(BuildDto).mockReturnValueOnce(buildDto);
185+
jest.mocked(BuildDto).mockReturnValueOnce(buildDto);
187186
service = await initService({ buildUpdateMock, eventsBuildUpdatedMock });
188187

189188
const result = await service.update(id, { isRunning: false });

src/compare/libs/pixelmatch/pixelmatch.service.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { TestingModule, Test } from '@nestjs/testing';
22
import { TestStatus } from '@prisma/client';
33
import Pixelmatch from 'pixelmatch';
44
import { PNG } from 'pngjs';
5-
import { mocked } from 'ts-jest/utils';
65
import { StaticService } from '../../../shared/static/static.service';
76
import { DIFF_DIMENSION_RESULT, EQUAL_RESULT, NO_BASELINE_RESULT } from '../consts';
87
import { DEFAULT_CONFIG, PixelmatchService } from './pixelmatch.service';
@@ -123,7 +122,7 @@ describe('getDiff', () => {
123122
const getImageMock = jest.fn().mockReturnValueOnce(image).mockReturnValueOnce(baseline);
124123
const diffName = 'diff name';
125124
const saveImageMock = jest.fn().mockReturnValueOnce(diffName);
126-
mocked(Pixelmatch).mockReturnValueOnce(5);
125+
jest.mocked(Pixelmatch).mockReturnValueOnce(5);
127126
service = await initService({ saveImageMock, getImageMock });
128127

129128
const result = await service.getDiff(
@@ -141,7 +140,7 @@ describe('getDiff', () => {
141140
}
142141
);
143142

144-
expect(mocked(Pixelmatch)).toHaveBeenCalledWith(
143+
expect(jest.mocked(Pixelmatch)).toHaveBeenCalledWith(
145144
new PNG({
146145
width: 2,
147146
height: 5,
@@ -185,7 +184,7 @@ describe('getDiff', () => {
185184
const saveImageMock = jest.fn();
186185
service = await initService({ saveImageMock, getImageMock });
187186
const pixelMisMatchCount = 150;
188-
mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);
187+
jest.mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);
189188

190189
const result = await service.getDiff(
191190
{
@@ -220,7 +219,7 @@ describe('getDiff', () => {
220219
});
221220
const getImageMock = jest.fn().mockReturnValueOnce(image).mockReturnValueOnce(baseline);
222221
const pixelMisMatchCount = 200;
223-
mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);
222+
jest.mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);
224223
const diffName = 'diff name';
225224
const saveImageMock = jest.fn().mockReturnValueOnce(diffName);
226225
service = await initService({

src/test-runs/test-runs.service.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { mocked } from 'ts-jest/utils';
21
import { Test, TestingModule } from '@nestjs/testing';
32
import { TestRunsService } from './test-runs.service';
43
import { PrismaService } from '../prisma/prisma.service';
@@ -320,7 +319,7 @@ describe('TestRunsService', () => {
320319
data: {
321320
image: testRun.imageName,
322321
baseline: testRun.baselineName,
323-
ignoreAreas: service['getAllIgnoteAreas'](testRun),
322+
ignoreAreas: service['getAllIgnoreAreas'](testRun),
324323
diffTollerancePercent: testRun.diffTollerancePercent,
325324
saveDiffAsFile: true,
326325
},
@@ -560,7 +559,7 @@ describe('TestRunsService', () => {
560559
expect(service.calculateDiff).toHaveBeenCalledWith(createTestRequestDto.projectId, testRun);
561560
expect(service['tryAutoApproveByPastBaselines']).toHaveBeenCalledWith({ testVariation, testRun });
562561
expect(service['tryAutoApproveByNewBaselines']).toHaveBeenCalledWith({ testVariation, testRun });
563-
expect(mocked(TestRunResultDto)).toHaveBeenCalledWith(testRun, testVariation);
562+
expect(jest.mocked(TestRunResultDto)).toHaveBeenCalledWith(testRun, testVariation);
564563
});
565564

566565
it('with baseLineName', async () => {
@@ -611,7 +610,7 @@ describe('TestRunsService', () => {
611610
expect(service.calculateDiff).toHaveBeenCalledWith(createTestRequestDto.projectId, testRun);
612611
expect(service['tryAutoApproveByPastBaselines']).toHaveBeenCalledWith({ testVariation, testRun });
613612
expect(service['tryAutoApproveByNewBaselines']).toHaveBeenCalledWith({ testVariation, testRun });
614-
expect(mocked(TestRunResultDto)).toHaveBeenCalledWith(testRun, testVariation);
613+
expect(jest.mocked(TestRunResultDto)).toHaveBeenCalledWith(testRun, testVariation);
615614
});
616615
});
617616

0 commit comments

Comments
 (0)