I'm new to writing unit tests and try to get some inspirations from "show-unit-tests" from the SDK, but "Query Features" is not working for me, and would like your input on both the syntax and conceptual design of the test.
I have created a custom map widget that access coordinates from another widget and draw a point (graphic in graphic layer) on the map.
The coordinates in the other widgets are passed in with code:
this.props.dispatch(appActions.widgetStatePropChange(this.props.id, 'X', value))this.props.dispatch(appActions.widgetStatePropChange(this.props.id, 'Y', value))
The coordinates are also shown as text above the map in the format of:
"X: <value> Y: <value>"
import { React, getAppStore, appActions } from 'jimu-core'
import _Widget from '../src/runtime/widget'
import { widgetRender, wrapWidget, getInitState, getDefaultAppConfig } from 'jimu-for-test'
const render = widgetRender()
jest.mock('jimu-core', () => {
return {
...jest.requireActual('jimu-core'),
loadArcGISJSAPIModule: jest.fn().mockImplementation(moduleId => {
let module
if (moduleId === 'esri/layers/GraphicLayer') {
module = jest.fn().mockImplementation(() => {
return {
//not sure what goes in here
}
})
}
return Promise.resolve(module)
})
}
})
describe('test map-view widget', () => {
it('test label, map from state', () => {
const Widget = wrapWidget(_Widget, { config: {} })
getAppStore().dispatch(appActions.updateStoreState(getInitState().merge({
appConfig: getDefaultAppConfig().merge({
widgets: {
w1: {
label: 123 // not working
}
}
})
})))
const renderResult = render(<Widget widgetId="w1" />)
expect(renderResult.queryByText('123')).toBeInTheDocument()
})
it('test api', async () => {
const { findByText } = render(<Widget widgetId="w2" />)
// Not sure what goes in here
})
})
Hello,
Did you ever find a resolution to this issue?
It would be really helpful learning.
Kind Regards,
Morgan