Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Update cell tests to just test that nothing is thrown #1397

Merged
merged 5 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './UserProfileCell.mock'

describe('UserProfileCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success userProfile={standard().userProfile} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success userProfile={standard().userProfile} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './UserProfileCell.mock'

describe('UserProfileCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success userProfile={standard().userProfile} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success userProfile={standard().userProfile} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './UserProfileCell.mock'

describe('UserProfileCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success userProfile={standard().userProfile} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success userProfile={standard().userProfile} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './UserCell.mock'

describe('UserCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success user={standard().user} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success user={standard().user} />)
}).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './UserProfileCell.mock'

describe('UserProfileCell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success userProfile={standard().userProfile} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success userProfile={standard().userProfile} />)
}).not.toThrow()
})
})
26 changes: 17 additions & 9 deletions packages/cli/src/commands/generate/cell/templates/test.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import { standard } from './${pascalName}Cell.mock'

describe('${pascalName}Cell', () => {
test('Loading renders successfully', () => {
render(<Loading />)
// Use screen.debug() to see output
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(() => {
render(<Loading />)
}).not.toThrow()
})

test('Empty renders successfully', async () => {
render(<Empty />)
expect(screen.getByText('Empty')).toBeInTheDocument()
expect(() => {
render(<Empty />)
}).not.toThrow()
})

test('Failure renders successfully', async () => {
render(<Failure error={new Error('Oh no')} />)
expect(screen.getByText(/Oh no/i)).toBeInTheDocument()
expect(() => {
render(<Failure error={new Error('Oh no')} />)
}).not.toThrow()
})

// When you're ready to test the actual output of your component render
// you could test that, for example, certain text is present:
//
// expect(screen.getByText('Hello, world')).toBeInTheDocument()

test('Success renders successfully', async () => {
render(<Success ${camelName}={standard().${camelName}} />)
expect(screen.getByText(/42/i)).toBeInTheDocument()
expect(() => {
render(<Success ${camelName}={standard().${camelName}} />)
}).not.toThrow()
})
})