Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Jest-dom like assertions #56

Open
distantnative opened this issue Dec 19, 2021 · 1 comment
Open

Jest-dom like assertions #56

distantnative opened this issue Dec 19, 2021 · 1 comment

Comments

@distantnative
Copy link

For component testing, would be great to have jest-dom like assertions, e.g. toHaveAttribute()

@wobsoriano
Copy link

wobsoriano commented Mar 30, 2022

I think you can just create a setup file and extend expect

// peeky.setup.ts
import { expect } from '@peeky/test'
import matchers from '@testing-library/jest-dom/matchers'

expect.extend(matchers)
// peeky.config.ts
import { defineConfig } from '@peeky/test'

export default defineConfig({
  runtimeEnv: 'dom',
  setupFiles: ['./peeky.setup.ts']
})
// tsconfig.json
{
  "compilerOptions": {
    ...
    "types": ["@peeky/test"]
  },
  "include": ["./peeky.setup.ts"]
}
import { render } from '@testing-library/vue';
import Counter from '~/src/components/Counter.vue'

describe('Component: Counter.vue', () => {
  test('User should see 0 at the beginning', () => {
    const { getByText } = render(Counter);
    const textNumberWrapper = getByText(/Counter is:/);
    expect(textNumberWrapper).toHaveTextContent('Counter is: 0');
  });
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants