Skip to content

Commit

Permalink
Merge pull request #370 from Laings-Online-Limited/switch-jest-to-vitest
Browse files Browse the repository at this point in the history
Replace Jest with Vitest for JavaScript testing
  • Loading branch information
DavidBiddle committed Jun 12, 2024
2 parents 9e6f40b + b38809a commit a99be25
Show file tree
Hide file tree
Showing 8 changed files with 2,569 additions and 4,876 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,14 @@ The app tests are written with [rspec-rails] and you can run them with:
bundle exec rspec
```

There are also unit tests for JavaScript code (look for files named `*.test.js`), written with [Jest]. You can run those with:
There are also unit tests for JavaScript code (look for files named `*.test.js`), written with [Vitest]. You can run those with:

```bash
npm run test

# For just the unit tests:
npm run test:unit

# to re-run the tests when files change:
npm run test:unit --watch

# For the functional tests:
npm run test:functional
```

[rspec-rails]: https://github.com/rspec/rspec-rails
[Jest]: https://jest.io
[Vitest]: https://vitest.dev/

### Linting

Expand Down
5 changes: 5 additions & 0 deletions app/frontend/javascript/components/cookie_banner.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @vitest-environment jsdom
*/

import { describe, beforeEach, test, expect } from 'vitest'
import { CookieBanner } from './cookie_banner.mjs'

describe('CookieBanner', () => {
Expand Down
7 changes: 6 additions & 1 deletion app/frontend/javascript/components/cookie_page.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @vitest-environment jsdom
*/

import { describe, beforeEach, test, expect } from 'vitest'
import { CookiePage } from './cookie_page.mjs'

describe('CookiePage', () => {
Expand Down Expand Up @@ -30,7 +35,7 @@ describe('CookiePage', () => {
cookiePage = new CookiePage(document.querySelector('[data-module="app-cookies-page"]'))
})

test('Initialzes ok when given valid html', () => {
test('Initializes ok when given valid html', () => {
expect(cookiePage).toBeDefined()
})
})
5 changes: 5 additions & 0 deletions app/frontend/javascript/services/cookie.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { loadConsentStatus, saveConsentStatus, COOKIE_NAME, CONSENT_STATUS } from './cookie.mjs'
import { describe, beforeEach, afterEach, it, expect } from 'vitest'

describe('Cookie', () => {
const cookieValue = `${COOKIE_NAME}=true`
Expand Down
5 changes: 5 additions & 0 deletions app/frontend/javascript/services/google_tag.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { deleteGoogleAnalyticsCookies, installAnalyticsScript } from './google_tag.mjs'
import { describe, afterEach, it, expect } from 'vitest'

describe('google_tag.mjs', () => {
afterEach(() => {
Expand Down
11 changes: 0 additions & 11 deletions jest.config.mjs

This file was deleted.

Loading

0 comments on commit a99be25

Please sign in to comment.