Skip to content

Commit

Permalink
feat(ng-mockito): switch to @typestrong/ts-mockito
Browse files Browse the repository at this point in the history
BREAKING CHANGE, see #46
  • Loading branch information
Markus-Ende committed Feb 8, 2023
1 parent 96c4c9f commit cc2dbf4
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
mockPipe,
mockProvider,
} from 'ng-mockito';
import { anyString, mock, when } from 'ts-mockito';
import { anyString, mock, when } from '@typestrong/ts-mockito';
import {
INTEGRATION_TEST_STRING_TOKEN,
INTEGRATION_TEST_INTERFACE_TOKEN,
Expand Down
11 changes: 9 additions & 2 deletions libs/ng-mockito/ng-mockito/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

# ng-mockito

**Type-safe mocking** for Angular, based on [ts-mockito](https://github.com/NagRock/ts-mockito). If you use ts-mockito for your Angular project, you'll love ng-mockito! If not, you'll love it anyway 🤓️. It also integrates nicely with [@testing-library/angular](https://github.com/testing-library/angular-testing-library).
> ⚠️ switched to [@typestrong/ts-mockito](https://www.npmjs.com/package/@typestrong/ts-mockito) because ts-mockito seems to not be maintained anymore (see https://github.com/NagRock/ts-mockito/issues/212)
> If you want to use this version of ng-mockito, you need to replace ts-mockito with @typestrong/ts-mockito:
>
> 1. `npm uninstall ts-mockito`.
> 2. `npm install @typestrong/ts-mockito`.
> 3. replace `'ts-mockito'` with `'@typestrong/ts-mockito'` in every file (no other changes should be necessary)
**Type-safe mocking** for Angular, based on [ts-mockito](https://github.com/TypeStrong/ts-mockito). If you use ts-mockito for your Angular project, you'll love ng-mockito! If not, you'll love it anyway 🤓️. It also integrates nicely with [@testing-library/angular](https://github.com/testing-library/angular-testing-library).

As a layer on top of ts-mockito, it's 100% compatible to it. You're still working with the usual functions (`when`, `verify`, ...).
It just makes your life easier when preparing mocks for Angular-specific types.
Expand Down Expand Up @@ -110,7 +117,7 @@ TestBed.configureTestingModule({
For more usage examples in combination with [@testing-library/angular](https://github.com/testing-library/angular-testing-library), please have a look at the [spec file in our GitHub repo](https://github.com/qupaya/ng-mockito/blob/main/libs/ng-mockito/integration/src/lib/integration-test.spec.ts).
For more information about how to mock, stub and verify, see the [ts-mockito documentation](https://github.com/NagRock/ts-mockito).
For more information about how to mock, stub and verify, see the [ts-mockito documentation](https://github.com/TypeStrong/ts-mockito).
---
Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@angular/core": ">=12",
"@angular/router": ">=12",
"@angular/platform-browser-dynamic": ">=12",
"ts-mockito": "^2.6.1",
"@typestrong/ts-mockito": "^2.6.0",
"typescript": ">=3.9.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { render } from '@testing-library/angular';
import * as tsMockito from 'ts-mockito';
import * as tsMockito from '@typestrong/ts-mockito';
import { mockComponent as _mockComponent } from './mock-component';
import { mockNg } from './mock-ng';

Expand Down
4 changes: 2 additions & 2 deletions libs/ng-mockito/ng-mockito/src/lib/mock-component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Component, EventEmitter } from '@angular/core';
import { instance, when } from 'ts-mockito';
import { instance, when } from '@typestrong/ts-mockito';
import {
getDirectiveProperties,
getDecoratorMetadata,
Expand Down Expand Up @@ -45,5 +45,5 @@ export function mockComponent<T>(
return instance(mock);
}

return (Component(metadata)(MockComponent) as unknown) as Type<T>;
return Component(metadata)(MockComponent) as unknown as Type<T>;
}
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Directive,
} from '@angular/core';
import { render } from '@testing-library/angular';
import * as tsMockito from 'ts-mockito';
import * as tsMockito from '@typestrong/ts-mockito';
import { mockDirective as _mockDirective } from './mock-directive';
import { mockNg } from './mock-ng';

Expand Down
4 changes: 2 additions & 2 deletions libs/ng-mockito/ng-mockito/src/lib/mock-directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Directive, EventEmitter } from '@angular/core';
import { instance, when } from 'ts-mockito';
import { instance, when } from '@typestrong/ts-mockito';
import {
getDecoratorMetadata,
getDirectiveProperties,
Expand Down Expand Up @@ -44,5 +44,5 @@ export function mockDirective<T>(
return instance(mock);
}

return (Directive(metadata)(MockDirective) as unknown) as Type<T>;
return Directive(metadata)(MockDirective) as unknown as Type<T>;
}
4 changes: 2 additions & 2 deletions libs/ng-mockito/ng-mockito/src/lib/mock-pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Pipe, PipeTransform } from '@angular/core';
import { render, screen } from '@testing-library/angular';
import * as tsMockito from 'ts-mockito';
import * as tsMockito from '@typestrong/ts-mockito';
import { mockPipe as _mockPipe } from './mock-pipe';
import { mockNg } from './mock-ng';

Expand Down Expand Up @@ -56,7 +56,7 @@ describe.each`
describe('when using a pipe with arguments', () => {
@Component({
template: `<span data-testID="pipeOutput">{{
'test' | test: 'arg'
'test' | test : 'arg'
}}</span>`,
})
class TestComponent {}
Expand Down
4 changes: 2 additions & 2 deletions libs/ng-mockito/ng-mockito/src/lib/mock-pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pipe } from '@angular/core';
import { instance } from 'ts-mockito';
import { instance } from '@typestrong/ts-mockito';
import { getDecoratorMetadata } from './ng-decorator-helpers';
import { createTypeAndMock, noOp } from './ts-mockito-helpers';
import { SetupMockFn, TypeOrMock, Type } from './types';
Expand All @@ -25,5 +25,5 @@ export function mockPipe<T>(

Pipe(metadata)(MockPipe);

return (MockPipe as unknown) as Type<T>;
return MockPipe as unknown as Type<T>;
}
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import * as tsMockito from 'ts-mockito';
import * as tsMockito from '@typestrong/ts-mockito';
import { mockNg } from './mock-ng';
import { mockProvider as _mockProvider } from './mock-provider';
import { ActivatedRoute } from '@angular/router';
Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FactoryProvider } from '@angular/core';
import { instance } from 'ts-mockito';
import { instance } from '@typestrong/ts-mockito';
import { createTypeAndMock, noOp } from './ts-mockito-helpers';
import { SetupMockFn, TypeOrMock } from './types';

Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-token.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { when, mock } from 'ts-mockito';
import { when, mock } from '@typestrong/ts-mockito';
import { mockNg } from './mock-ng';
import { mockToken as _mockToken } from './mock-token';

Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/mock-token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { FactoryProvider, InjectionToken, Type } from '@angular/core';
import { instance, mock } from 'ts-mockito';
import { instance, mock } from '@typestrong/ts-mockito';
import {
createDefaultValue,
getConstructorParameterTypeOfInjectionToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { DOCUMENT } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { InjectionToken, Renderer2 } from '@angular/core';
import { instance, mock, when } from 'ts-mockito';
import { instance, mock, when } from '@typestrong/ts-mockito';
import { createTypeAndMock, isStubbed, isMock } from './ts-mockito-helpers';

describe('ts-mockito helpers', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/ng-mockito/ng-mockito/src/lib/ts-mockito-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { InjectionToken } from '@angular/core';
import { mock } from 'ts-mockito';
import { mock } from '@typestrong/ts-mockito';
import { Mocker } from 'ts-mockito/lib/Mock';
import { TypeAndMock, TypeOrMock, Type } from './types';

Expand Down
52 changes: 33 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@types/node": "18.13.0",
"@typescript-eslint/eslint-plugin": "5.51.0",
"@typescript-eslint/parser": "5.51.0",
"@typestrong/ts-mockito": "^2.6.5",
"codelyzer": "^6.0.0",
"cypress": "^9.6.1",
"dotenv": "10.0.0",
Expand All @@ -95,7 +96,6 @@
"prettier": "2.8.3",
"semantic-release": "^20.1.0",
"ts-jest": "28.0.8",
"ts-mockito": "^2.6.1",
"ts-node": "10.9.1",
"tslint": "6.1.3",
"typescript": "4.8.4"
Expand Down

0 comments on commit cc2dbf4

Please sign in to comment.