Skip to content

Commit

Permalink
Merge pull request #43 from afontcu/master
Browse files Browse the repository at this point in the history
Improve onboarding by adding explanations
  • Loading branch information
afontcu authored Jun 21, 2019
2 parents 07bdd1b + 3d09b68 commit f7bb066
Show file tree
Hide file tree
Showing 37 changed files with 163 additions and 224 deletions.
24 changes: 19 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"author": "Daniel Cook",
"license": "MIT",
"dependencies": {
"@testing-library/dom": "^5.0.1",
"@testing-library/dom": "^5.2.0",
"@vue/test-utils": "^1.0.0-beta.29",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
Expand Down
9 changes: 9 additions & 0 deletions tests/__tests__/__snapshots__/axios-mock.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`makes an API call and displays the greeting when load-greeting is clicked 1`] = `
<div><button>
Fetch
</button> <span>
hello there
</span></div>
`;
9 changes: 0 additions & 9 deletions tests/__tests__/__snapshots__/fetch.js.snap

This file was deleted.

27 changes: 27 additions & 0 deletions tests/__tests__/axios-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import axiosMock from 'axios'
import { render, fireEvent } from '@testing-library/vue'
import Component from './components/Fetch.vue'
import 'jest-dom/extend-expect'

test('makes an API call and displays the greeting when load-greeting is clicked', async () => {
axiosMock.get.mockImplementationOnce(() =>
Promise.resolve({
data: { greeting: 'hello there' }
})
)

const { html, getByText } = render(Component, { props: { url: '/greeting' } })

// Act
await fireEvent.click(getByText('Fetch'))

expect(axiosMock.get).toHaveBeenCalledTimes(1)
expect(axiosMock.get).toHaveBeenCalledWith('/greeting')
getByText('hello there')

// You can render component snapshots by using html(). However, bear in mind
// that Snapshot Testing should not be treated as a replacement for regular
// tests.
// More about the topic: https://twitter.com/searls/status/919594505938112512
expect(html()).toMatchSnapshot()
})
16 changes: 2 additions & 14 deletions tests/__tests__/components/Button.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
<template>
<button :class="typeClass" @click="handleClick">{{ text }}</button>
<button @click="handleClick">{{ text }}</button>
</template>

<script>
export default {
props: {
text: {
type: String,
default: ''
},
type: {
validator: value => ['primary', 'secondary'].includes(value),
default: 'primary'
}
},
computed: {
typeClass: function() {
if (this.type) {
return `button button--${this.type}`
}
return 'button'
required: true
}
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<template>
<div>
<div v-if="loading">Loading...</div>
<div v-else data-testid="message">
Loaded this message: {{ data.returnedMessage }}
</div>
</div>
<p v-if="loading">Loading...</p>
<p v-else data-testid="message">
Loaded this message: {{ data.returnedMessage }}
</p>
</template>

<script>
Expand All @@ -13,6 +11,7 @@ const fetchAMessage = () =>
// we are using random timeout here to fireEvent a real-time example
// of an async operation calling a callback at a non-deterministic time
const randomTimeout = Math.floor(Math.random() * 100)
setTimeout(() => {
resolve({ returnedMessage: 'Hello World' })
}, randomTimeout)
Expand Down
4 changes: 2 additions & 2 deletions tests/__tests__/components/Fetch.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div>
<button data-testid="load-greeting" @click="fetch">
<button @click="fetch">
Fetch
</button>
<span v-if="data" data-testid="greeting-text">
<span v-if="data">
{{ data.greeting }}
</span>
</div>
Expand Down
1 change: 0 additions & 1 deletion tests/__tests__/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
v-model="recommend"
type="checkbox"
name="recommend"
data-testid="recommend-checkbox"
/>

<button :disabled="submitDisabled" type="submit">
Expand Down
2 changes: 1 addition & 1 deletion tests/__tests__/components/StopWatch.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<span data-testid="elapsed">{{ lapse }}ms</span>
<button data-testid="start-stop-button" @click="handleRunClick">
<button @click="handleRunClick">
{{ running ? 'Stop' : 'Start' }}
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/__tests__/components/Validate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
aria-labelledby="username-label"
/>

<span v-show="errors.has('username')" data-testid="username-errors">{{
<span v-if="errors.has('username')" data-testid="username-errors">{{
errors.first('username')
}}</span>

Expand Down
3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/AltText.vue

This file was deleted.

5 changes: 0 additions & 5 deletions tests/__tests__/components/queries/Attribute.vue

This file was deleted.

3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/Empty.vue

This file was deleted.

6 changes: 0 additions & 6 deletions tests/__tests__/components/queries/GetByAltText.vue

This file was deleted.

3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/JestHelpers.vue

This file was deleted.

13 changes: 0 additions & 13 deletions tests/__tests__/components/queries/LabelText.vue

This file was deleted.

3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/LabelWithNoFormControl.vue

This file was deleted.

3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/Placeholder.vue

This file was deleted.

3 changes: 0 additions & 3 deletions tests/__tests__/components/queries/TotallyEmptyLabel.vue

This file was deleted.

21 changes: 0 additions & 21 deletions tests/__tests__/components/queries/index.js

This file was deleted.

28 changes: 28 additions & 0 deletions tests/__tests__/disappearance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render, waitForElementToBeRemoved } from '@testing-library/vue'
import Disappearance from './components/Disappearance'
import 'jest-dom/extend-expect'

test('it waits for the data to be loaded', async () => {
const { getByText, queryByText, queryByTestId } = render(Disappearance)

// Assert initial state
getByText('Loading...')
expect(queryByText(/Loaded this message/)).not.toBeInTheDocument()

// Line reads as follows "Wait until element with test 'Loading...' is gone."
await waitForElementToBeRemoved(() => queryByText('Loading...'))
// It is equivalent to:
//
// await wait(() => {
// expect(queryByText('Loading...')).not.toBeInTheDocument()
// })
//
// `wait()` waits until the callback function passes or times out.

// After 'Loading...' element is gone, we can assert that fetched data is
// rendered.
expect(queryByTestId('message')).toHaveTextContent(/Hello World/)

// Read more about async utilities:
// https://testing-library.com/docs/dom-testing-library/api-async
})
11 changes: 0 additions & 11 deletions tests/__tests__/end-to-end.js

This file was deleted.

22 changes: 0 additions & 22 deletions tests/__tests__/fetch.js

This file was deleted.

5 changes: 3 additions & 2 deletions tests/__tests__/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('Review form submits', async () => {
const {
getByLabelText,
getByText,
getByTestId,
getByRole,
getByDisplayValue,
getByPlaceholderText,
emitted
Expand Down Expand Up @@ -44,7 +44,8 @@ test('Review form submits', async () => {
const genreSelect = getByDisplayValue('Comedy')
await fireEvent.update(genreSelect, fakeReview.genre)

const recommendInput = getByTestId('recommend-checkbox')
// Get the Input element by its implicit ARIA role.
const recommendInput = getByRole('checkbox')
await fireEvent.update(recommendInput, fakeReview.recommend)

// NOTE: in jsdom, it's not possible to trigger a form submission
Expand Down
15 changes: 0 additions & 15 deletions tests/__tests__/number-display.js

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions tests/__tests__/router/programmatic-routing/components/App.vue

This file was deleted.

Loading

0 comments on commit f7bb066

Please sign in to comment.