Skip to content

Commit

Permalink
(fix) unit test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dreyliky committed Jan 20, 2023
1 parent 091082e commit d895a87
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ speed-measure-plugin*.json
.settings/
*.sublime-workspace

.vs

# IDE - VSCode
.vscode/*
!.vscode/settings.json
Expand Down
5 changes: 2 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
Expand Down Expand Up @@ -168,7 +167,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/app/library/src/test.ts",
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "src/app/library/tsconfig.spec.json",
"karmaConfig": "src/app/library/karma.conf.js"
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"build:library": "ng build library --configuration production && node scripts/on-library-builded.js",
"build:doc": "npm run build:doc-library && npm run build:doc-showcase",
"build:doc-library": "compodoc -c compodoc-lib-config.json",
"build:doc-showcase": "compodoc -c compodoc-showcase-config.json",
"test:library": "ng test library"
"build:doc-showcase": "compodoc -c compodoc-showcase-config.json"
},
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { DOCUMENT } from '@angular/common';
import { TestBed } from '@angular/core/testing';
import { AccentColorService } from './accent-color.service';

describe('AccentColorService', () => {
let service: AccentColorService;
let documentElement: HTMLElement;

beforeEach(() => {
const module = TestBed.configureTestingModule({
providers: [AccentColorService]
});

service = module.inject(AccentColorService);
documentElement = module.inject(DOCUMENT).documentElement;
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should get color value from CSS variable', () => {
const colorType = 'primary';
const cssColor = '255, 255, 255';

documentElement.style.setProperty(`--os-${colorType}-color`, cssColor);

expect(service.get(colorType)).toEqual({ r: 255, g: 255, b: 255 });
});

it('should set color value into CSS variable', () => {
const colorType = 'primary';
const color = { r: 255, g: 255, b: 255 };

service.apply(colorType, color);

expect(
documentElement.style
.getPropertyValue(`--os-${colorType}-color`)
)
.toEqual('255, 255, 255');
});
});
28 changes: 0 additions & 28 deletions src/app/library/test.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/app/library/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"enableResourceInlining": true
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
7 changes: 4 additions & 3 deletions src/app/library/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "./",
"baseUrl": "./",
"outDir": "../../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"files": [],
"include": [
"./modules/shared.module.spec.ts",
"**/*.spec.ts",
"**/*.d.ts"
]
Expand Down
27 changes: 0 additions & 27 deletions src/test.ts

This file was deleted.

1 change: 0 additions & 1 deletion tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
Expand Down

0 comments on commit d895a87

Please sign in to comment.