Skip to content

Commit e602326

Browse files
committed
Update tests
1 parent 5b99ba6 commit e602326

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

packages/anvil-embed-frame/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ref = iframeRef || useRef(null)
2727
return () => {
2828
window.removeEventListener('message', handleEvent)
2929
}
30-
}, [anvilURL, onEvent, scroll])
30+
}, [ anvilURL, onEvent, ref, scroll])
3131

3232
return (
3333
<iframe
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,75 @@
11
import React from 'react'
22
import AnvilEmbedFrame from '../../src/index'
3+
import { expect } from 'chai' // Assuming you're using Chai for assertions
34

45
describe('AnvilEmbedFrame', function () {
5-
def('handleEvent', () => sinon.spy())
6-
def('anvilURL', 'https://app.useanvil.com')
6+
let handleEvent
7+
const anvilURL = 'https://app.useanvil.com'
8+
const event = new window.Event('message', { bubbles: true })
79

8-
def('render', () => shallow(
9-
<AnvilEmbedFrame
10-
iframeURL="http://localhost"
11-
onEvent={$.handleEvent}
12-
anvilURL={$.anvilURL}
13-
/>,
14-
))
10+
beforeEach(() => {
11+
handleEvent = sinon.spy()
12+
})
1513

16-
it('renders', async function () {
17-
const wrapper = $.render
18-
expect(wrapper).to.exist
19-
expect(wrapper.find('iframe')).to.exist
14+
it('renders', function () {
15+
const wrapper = shallow(
16+
<AnvilEmbedFrame
17+
iframeURL="http://localhost"
18+
onEvent={handleEvent}
19+
anvilURL={anvilURL}
20+
/>
21+
)
22+
expect(wrapper.exists()).to.be.true
23+
expect(wrapper.find('iframe').exists()).to.be.true
2024
})
2125

22-
describe('onEvent', function () {
23-
it('does not call onEvent when non-anvil url passed in', async function () {
26+
describe('handleEvent', function () {
27+
it('does not call onEvent when non-anvil url passed in', function () {
2428
const origin = 'https://chess.com'
2529
const data = { action: 'forgeComplete' }
26-
const wrapper = $.render
27-
wrapper.instance().handleEvent({ origin, data })
28-
expect($.handleEvent).to.not.have.been.called
30+
mount(
31+
<AnvilEmbedFrame
32+
iframeURL="http://localhost"
33+
onEvent={handleEvent}
34+
anvilURL={anvilURL}
35+
/>
36+
)
37+
event.data = data
38+
event.origin = origin
39+
window.dispatchEvent(event)
40+
expect(handleEvent.called).to.be.false
2941
})
3042

31-
it('does not call onEvent when non-object data passed in', async function () {
32-
const origin = $.anvilURL
43+
it('does not call onEvent when non-object data passed in', function () {
44+
const origin = anvilURL
3345
const data = 'signerComplete'
34-
const wrapper = $.render
35-
wrapper.instance().handleEvent({ origin, data })
36-
expect($.handleEvent).to.not.have.been.called
46+
mount(
47+
<AnvilEmbedFrame
48+
iframeURL="http://localhost"
49+
onEvent={handleEvent}
50+
anvilURL={anvilURL}
51+
/>
52+
)
53+
event.data = data
54+
event.origin = origin
55+
window.dispatchEvent(event)
56+
expect(handleEvent.called).to.be.false
3757
})
3858

39-
it('calls onEvent successfully', async function () {
40-
const origin = $.anvilURL
59+
it('calls onEvent successfully', function () {
60+
const origin = anvilURL
4161
const data = { action: 'castEdit' }
42-
const wrapper = $.render
43-
wrapper.instance().handleEvent({ origin, data })
44-
expect($.handleEvent).to.have.been.calledWith(data)
62+
mount(
63+
<AnvilEmbedFrame
64+
iframeURL="http://localhost"
65+
onEvent={handleEvent}
66+
anvilURL={anvilURL}
67+
/>
68+
)
69+
event.data = data
70+
event.origin = origin
71+
window.dispatchEvent(event)
72+
expect(handleEvent.calledWith(data)).to.be.true
4573
})
4674
})
4775
})

0 commit comments

Comments
 (0)