我正在对Vue中的Jest和Element-ui进行单元测试,该组件包含一个带有2个选项的select。我从下拉菜单中选择一个选项,然后检查是否已调用操作。
1)使用normal select和optionHTML标签,可以完美地工作。
// Fruit.vue
<template lang="pug">
select(
v-model="fruit"
)
option(
v-for="item in fruits"
:label="item.label"
:value="item.value"
)
</template>
<script>
export default {
data () {
return {
fruits: [
{
label: 'Banana',
value: false
},
{
label: 'Apple',
value: false
}
]
}
},
computed: {
fruit: {
get () {
return this.$store.state.fruit
},
set (fruit) {
this.$store.dispatch('setSelectedFruit', { fruit })
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
// DOM
<select>
<option label="Banana" value="false"></option>
<option label="Apple" value="false"></option>
</select>
Run Code Online (Sandbox Code Playgroud)
// …
我正在尝试对 DynamoDB 进行查询,如果LastEvaluatedKey返回 a (意味着查询超过 1 MB),我想进行其他查询,以便从表中获取所有所需的数据,并使用LastEvaluatedKeyasExclusiveStartKey进行下一个查询。这是我现在的代码:
query_response = table.query(
KeyConditionExpression=Key('brand').eq(brand)
)
pagination_key = None
if 'LastEvaluatedKey' in query_response:
pagination_key = query_response['LastEvaluatedKey']
while pagination_key:
next_query_response = table.query(
KeyConditionExpression=Key('brand').eq(brand),
ExclusiveStartKey=pagination_key
)
Run Code Online (Sandbox Code Playgroud)
但是,我想通过将查询提取到方法中并将其 pagination_key 作为参数传递来重构此代码。为此,我必须能够在第一次调用时设置为ExclusiveStartKey或False其他None一些默认值,但我没有找到任何相关内容,或者我必须能够将所有这些都排除ExclusiveStartKey在外,但我也不知道该怎么做。
在Vue中,我想检查商店中的某个动作是否正确地使用Jest's调用了另一个动作spyOn,我以不同的方式尝试了它,但是它似乎不起作用,这是我的代码:
// index.js
getRecipes ({ dispatch }) {
const fruits = ['apple', 'banana', 'pear']
fruits.forEach((fruit) => {
dispatch('getRecipe', fruit)
})
},
async getRecipe ({ commit }) {
const recipe = await recipesService.fetchRecipe(payload)
commit(SET_RECIPE, { recipe })
},
Run Code Online (Sandbox Code Playgroud)
// index.spec.js
test('getRecipes calls getRecipe 3 times, each with the right fruit', () => {
const commit = jest.fn()
const dispatch = jest.fn()
const spy = spyOn(actions, 'getRecipe')
const result = actions.getRecipes({ commit, dispatch })
expect(spy).toHaveBeenCalledTimes(3)
expect(spy).toHaveBeenCalledWith('apple')
})
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时,这是我得到的输出:
Expected spy …Run Code Online (Sandbox Code Playgroud)