Skip to content

Commit 3bcdf63

Browse files
authored
added test helpers (#43)
* added test helpers * 17.1.0 * depups * remove beta hold * ci tweak * remove coveralls * run tests against real project * add step * update name * fix * fix * fix
1 parent c2638f9 commit 3bcdf63

File tree

7 files changed

+293
-183
lines changed

7 files changed

+293
-183
lines changed

.circleci/config.yml

+45-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: 2.1
22
orbs:
3-
coveralls: coveralls/coveralls@2.2.1
3+
browser-tools: circleci/browser-tools@1
4+
# coveralls: coveralls/coveralls@2.2.1
45
jobs:
56
build:
67
docker:
@@ -39,17 +40,6 @@ jobs:
3940
- run:
4041
name: Run Tests and Check Code Coverage
4142
command: npm run test:ci
42-
environment:
43-
JEST_JUNIT_OUTPUT_DIR: ./test_results/
44-
- store_test_results:
45-
path: ./test_results
46-
- store_artifacts:
47-
path: ./coverage
48-
49-
# upload coverage report to coveralls for readme badge support
50-
# requires config.yml version 2.1 and orbs: coveralls: coveralls/coveralls@1.0.4
51-
# requires coveralls account and token specific to repo to be stored in CircleCI
52-
#- coveralls/upload
5343

5444
- run: npm run build
5545
- run: npm pack
@@ -68,6 +58,32 @@ jobs:
6858
root: /tmp/workspace
6959
paths:
7060
- pkg
61+
test-with-project:
62+
docker:
63+
- image: cimg/node:lts-browsers
64+
working_directory: ~/
65+
steps:
66+
- attach_workspace:
67+
at: /tmp/workspace
68+
- run:
69+
name: Setup lemon-mart
70+
command: |
71+
git clone https://github.com/duluca/lemon-mart
72+
cd lemon-mart
73+
npm ci
74+
- browser-tools/install-chrome
75+
- browser-tools/install-chromedriver
76+
- run:
77+
name: Apply angular-unit-test-helper
78+
command: |
79+
set -exu
80+
cd lemon-mart
81+
npm install /tmp/workspace/pkg/angular-unit-test-helper-*.tgz
82+
- run:
83+
name: Run lemon-mart tests
84+
command: |
85+
cd lemon-mart
86+
npx ng test --watch=false --project lemon-mart
7187
deploy:
7288
docker:
7389
- image: cimg/node:lts
@@ -101,25 +117,31 @@ workflows:
101117
build-and-deploy:
102118
jobs:
103119
- build
104-
- hold:
105-
type: approval
120+
- test-with-project:
106121
requires:
107122
- build
108123
filters:
109124
branches:
110-
only: main
111-
- deploy:
112-
context: npm
113-
requires:
114-
- hold
115-
- hold-beta:
125+
ignore: main
126+
- hold:
116127
type: approval
117128
requires:
118129
- build
119130
filters:
120131
branches:
121-
ignore: main
122-
- deploy-beta:
132+
only: main
133+
- deploy:
123134
context: npm
124135
requires:
125-
- hold-beta
136+
- hold
137+
# - hold-beta:
138+
# type: approval
139+
# requires:
140+
# - build
141+
# filters:
142+
# branches:
143+
# ignore: main
144+
# - deploy-beta:
145+
# context: npm
146+
# requires:
147+
# - hold-beta

.vscode/settings.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"editor.formatOnSave": true,
2121
"editor.minimap.enabled": false,
2222
"editor.codeActionsOnSave": {
23-
"source.organizeImports": false,
24-
"source.fixAll.tslint": true
23+
"source.organizeImports": "never",
24+
"source.fixAll.tslint": "explicit"
2525
},
2626
"editor.defaultFormatter": "esbenp.prettier-vscode",
2727
"explorer.openEditors.visible": 0,
@@ -37,5 +37,6 @@
3737
},
3838
"[ignore]": {
3939
"editor.defaultFormatter": "foxundermoon.shell-format"
40-
}
40+
},
41+
"angular.enable-strict-mode-prompt": false
4142
}

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ Replaces boilerplate
152152
class MockCurrentWeatherComponent {}
153153
```
154154

155+
### `getNativeElementByTestId<TComponent>(fixture: ComponentFixture<TComponent>, testId: string = '')`
156+
157+
Helper function to retrieve the native element associated with a specific `data-testid`` within a component fixture.
158+
159+
Usage
160+
161+
```html
162+
<span class="left-pad" data-testid="title">LemonMart</span>
163+
```
164+
165+
```ts
166+
it('should render title', () => {
167+
const fixture = TestBed.createComponent(AppComponent)
168+
fixture.detectChanges()
169+
const titleElement = getNativeElementByTestId(fixture, 'title')
170+
expect(titleElement.textContent).toContain('LemonMart')
171+
})
172+
```
173+
155174
### `injectClass<TDependency>(dependency: Type<TDependency> | AbstractType<TDependency>): TDependency`
156175

157176
Helper function to inject a dependency, like a service, into the TestBed with a typed return variable.

0 commit comments

Comments
 (0)