forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsx-spec.js
34 lines (29 loc) · 886 Bytes
/
jsx-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// a few exploratory tests to go with
// https://softchris.github.io/books/react/jsx/
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
const Elem = () => <h1>Some title</h1>
it('has title attribute', () => {
mount(<Elem title="a title"></Elem>)
cy.contains('h1', 'Some title') // the element contains header
})
it('calls React.createElement with props and text', () => {
cy.spy(React, 'createElement')
mount(<Elem title="a title"></Elem>).then(() => {
expect(React.createElement).to.have.been.calledWith(Elem, {
title: 'a title',
})
})
})
it('renders fragments', () => {
const ElemFragment = () => (
<React.Fragment>
<h1>Some title</h1>
<div>Some content</div>
</React.Fragment>
)
mount(<ElemFragment />)
cy.contains('h1', 'Some title')
cy.contains('Some content')
})