|
1 | 1 | import { useContext } from 'react' |
2 | 2 | import { renderHook } from '@testing-library/react-hooks' |
3 | | -import { Map } from 'azure-maps-control' |
| 3 | +import atlas, { Map } from 'azure-maps-control' |
4 | 4 | import React from 'react' |
5 | 5 | import { AzureMapsContext } from '../contexts/AzureMapContext' |
6 | 6 | import { |
@@ -65,30 +65,36 @@ describe('AzureMapDataSourceProvider tests', () => { |
65 | 65 | const { result } = renderHook(() => useContextConsumer(), { |
66 | 66 | wrapper: wrapWithDataSourceContext({ id: 'id', dataFromUrl: 'dataFromUrl' }) |
67 | 67 | }) |
68 | | - expect(result.current.dataSourceRef?.importDataFromUrl).toHaveBeenCalledWith('dataFromUrl') |
| 68 | + expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource) |
| 69 | + expect((result.current.dataSourceRef as atlas.source.DataSource).importDataFromUrl).toHaveBeenCalledWith('dataFromUrl') |
69 | 70 | }) |
70 | 71 |
|
71 | 72 | it('should call add collection if collection was not falsy', () => { |
72 | 73 | const { result } = renderHook(() => useContextConsumer(), { |
73 | 74 | wrapper: wrapWithDataSourceContext({ id: 'id', collection: [] }) |
74 | 75 | }) |
75 | | - expect(result.current.dataSourceRef?.add).toHaveBeenCalledWith([]) |
76 | | - expect(result.current.dataSourceRef?.clear).toHaveBeenCalledWith() |
| 76 | + expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource) |
| 77 | + const dataSourceRef = result.current.dataSourceRef as atlas.source.DataSource |
| 78 | + expect(dataSourceRef.add).toHaveBeenCalledWith([]) |
| 79 | + expect(dataSourceRef.clear).toHaveBeenCalledWith() |
77 | 80 | }) |
78 | 81 |
|
79 | 82 | it('should call add collection and clear method if collection was changed', () => { |
80 | 83 | const { result, rerender } = renderHook(() => useContextConsumer(), { |
81 | 84 | wrapper: wrapWithDataSourceContext({ id: 'id', collection: [] }) |
82 | 85 | }) |
83 | 86 | rerender({}) |
84 | | - expect(result.current.dataSourceRef?.add).toHaveBeenCalledTimes(2) |
85 | | - expect(result.current.dataSourceRef?.clear).toHaveBeenCalledTimes(1) |
| 87 | + expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource) |
| 88 | + const dataSourceRef = result.current.dataSourceRef as atlas.source.DataSource |
| 89 | + expect(dataSourceRef.add).toHaveBeenCalledTimes(2) |
| 90 | + expect(dataSourceRef.clear).toHaveBeenCalledTimes(1) |
86 | 91 | }) |
87 | 92 |
|
88 | 93 | it('should call setOptions and clear method if options was changed', () => { |
89 | 94 | const { result, rerender } = renderHook(() => useContextConsumer(), { |
90 | 95 | wrapper: wrapWithDataSourceContext({ id: 'id', options: { option: 'option' } }) |
91 | 96 | }) |
92 | | - expect(result.current.dataSourceRef?.setOptions).toHaveBeenLastCalledWith({ option: 'option' }) |
| 97 | + expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource) |
| 98 | + expect((result.current.dataSourceRef as atlas.source.DataSource).setOptions).toHaveBeenLastCalledWith({ option: 'option' }) |
93 | 99 | }) |
94 | 100 | }) |
0 commit comments