|
1 | 1 | import{shallow}from'vue-test-utils';
|
2 | 2 | importCaCodeSnippetfrom'./CaCodeSnippet.vue';
|
3 | 3 |
|
| 4 | +jest.useFakeTimers(); |
| 5 | + |
4 | 6 | describe('CaCodeSnippet',()=>{
|
| 7 | +letwrapper; |
| 8 | + |
| 9 | +beforeEach(()=>{ |
| 10 | +wrapper=shallow(CaCodeSnippet); |
| 11 | +}); |
| 12 | + |
5 | 13 | test('is a Vue instance',()=>{
|
6 |
| -constwrapper=shallow(CaCodeSnippet); |
7 | 14 | expect(wrapper.isVueInstance()).toBeTruthy();
|
8 | 15 | });
|
9 | 16 |
|
10 | 17 | test('Mathes snapshot',()=>{
|
11 |
| -constwrapper=shallow(CaCodeSnippet); |
12 |
| -expect(wrapper.html()).toMatchSnapshot() |
| 18 | +expect(wrapper.html()).toMatchSnapshot(); |
| 19 | +}); |
| 20 | + |
| 21 | +describe('when clicked on copy button',()=>{ |
| 22 | +beforeEach(()=>{ |
| 23 | +document.createRange=()=>({ |
| 24 | +selectNode:()=>{}, |
| 25 | +}); |
| 26 | +window.getSelection=()=>({ |
| 27 | +addRange:()=>{}, |
| 28 | +removeAllRanges:()=>{}, |
| 29 | +}); |
| 30 | +}); |
| 31 | + |
| 32 | +describe('if copy succeeds',()=>{ |
| 33 | +beforeEach(()=>{ |
| 34 | +document.execCommand=jest.fn(()=>true); |
| 35 | +wrapper.find('button').trigger('click'); |
| 36 | +}); |
| 37 | + |
| 38 | +it('should call the copy api',()=>{ |
| 39 | +expect(document.execCommand).toHaveBeenCalledWith('copy'); |
| 40 | +}); |
| 41 | + |
| 42 | +it('should show the feedback',()=>{ |
| 43 | +expect(wrapper.vm.$data.showFeedback).toBe(true); |
| 44 | +}); |
| 45 | + |
| 46 | +describe('after 2 seconds',()=>{ |
| 47 | +beforeEach(()=>{ |
| 48 | +jest.advanceTimersByTime(2000); |
| 49 | +}); |
| 50 | + |
| 51 | +it('should hide the feedback',()=>{ |
| 52 | +expect(wrapper.vm.$data.showFeedback).toBe(false); |
| 53 | +}); |
| 54 | +}); |
| 55 | +}); |
13 | 56 | });
|
14 |
| -}) |
| 57 | +}); |