-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Takes care of the lack of reactivity seen in #119
- Loading branch information
Showing
6 changed files
with
46 additions
and
12 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
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,17 @@ | ||
<script> | ||
// The text content of the paragraph is purposely not bound | ||
// with any svelte variable. The purpose of this exercise | ||
// is to reduce to the simplest form my use-case which is | ||
// to test changes done in html elements of a svelte component | ||
// by external helper class methods, which do not allow for | ||
// bindings to exist. | ||
const modify = () => { | ||
const par = document.querySelector(".info"); | ||
par.innerText = "Modified by click"; | ||
}; | ||
</script> | ||
|
||
<div> | ||
<p class="info" data-testid="info">Click to modify</p> | ||
<button on:click={modify} label="button">Modify</button> | ||
</div> |
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,17 @@ | ||
import userEvent from '@testing-library/user-event' | ||
import { expect, test } from 'vitest' | ||
|
||
import { render, screen, waitFor } from '../pure.js' | ||
import Component from './fixtures/NonBound.svelte' | ||
|
||
// fails with jsdom, but work with happy-dom | ||
|
||
test('should modify the text after clicking the button', async () => { | ||
render(Component) | ||
const button = screen.getByRole('button') | ||
userEvent.click(button) | ||
const info = screen.getByTestId('info') | ||
|
||
// The test fails independently of using waitFor or not. | ||
await waitFor(() => expect(info).toHaveTextContent('Modified by click')) | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* @jest-environment jsdom | ||
* @jest-environment happy-dom | ||
*/ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
|
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