-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from mbland/use-jsdom-environment
Add initApp test, fragment helper, page object
- Loading branch information
Showing
4 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-env browser, node, jest, vitest */ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
import initApp from './init' | ||
import { describe, expect, test } from 'vitest' | ||
import { fragment } from './test-helpers.js' | ||
import StringCalculatorPage from './test-page.js' | ||
|
||
// @vitest-environment jsdom | ||
describe('initial state after calling initApp', () => { | ||
test('contains the "Hello, World!" placeholder', async () => { | ||
const document = fragment('<div id="app"></div>') | ||
|
||
initApp(window, document) | ||
|
||
const e = new StringCalculatorPage(document).getPlaceholder() | ||
expect(e.textContent).toContain('Hello, World!') | ||
expect(e.href).toContain('%22Hello,_World!%22') | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-env browser */ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
/** | ||
* Represents the StringCalculator web page. | ||
* | ||
* Follows the Page Object pattern from the Selenium WebDriver documentation, | ||
* though we're using the DOM directly rather than Selenium. | ||
* @see https://www.selenium.dev/documentation/test_practices/design_strategies/ | ||
*/ | ||
export default class StringCalculatorPage { | ||
document | ||
|
||
constructor(doc) { | ||
this.document = doc | ||
} | ||
|
||
getPlaceholder() { | ||
return this.document.querySelector('#app .placeholder a') | ||
} | ||
} |