我正在测试一个返回整数的实用函数,我正在尝试模拟调用它,但是即使经过数小时的搜索,我仍然找不到正确的方法。
我也尝试过`$wp_customize->add_section( 'the_event_secction_name' , array(
'title' => __( 'My Section Name', 'starter' ),
'priority' => 30
) );
$wp_customize->add_setting( 'starter_new_setting_name' , array(
'default' => '#000000',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
'label' => __( 'Header Color', 'starter' ),
'section' => 'the_event_secction_name',
'settings' => 'starter_new_setting_name',
) ) );`
,但似乎没有用。
Authentication.js
spyOn()
Authentication.test.js
export function auth(username) {
AsyncStorage.getItem('@app:id').then((id) => {
if (id === username) {
return 1;
}
return 0;
});
}
我希望模拟调用import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer'; // Note: test renderer must be required after react-native.
import mockAxios from 'axios';
import mockAsyncStorage from '@react-native-community/async-storage';
import auth from '../App/Utils/Authorization';
test('should check whether the user whose username is entered as a paramter is the same as the user logged in the application', () => {
auth = jest.fn();
expect(auth).toHaveReturned();
expect(mockAsyncStorage.getItem).toHaveBeenCalledTimes(1);
expect(mockAsyncStorage.multiRemove).toHaveBeenCalledWith('@app:id');
});
并获得成功的测试,相反,每运行auth()
时都会得到一个错误"auth" is read-only
作为输出。
答案 0 :(得分:0)
您正在重新分配导入的成员emailsent
,而不是以应有的方式使用SELECT dealercode,
coupon_name,
emailsent,
responders,
responserate,
rn = rank() OVER (PARTITION BY dealercode,
coupon_name
ORDER BY responserate DESC,
emailsent DESC)
FROM table123;
。调用jest模拟函数将返回未定义状态,相反,您可以使用mockFn.mockImplementation(fn)将函数绑定到模拟并测试其是否正在被调用或返回某个期望值。
auth
您可以验证函数检查mockFn.mock.results的输出,该检查存储通过调用函数进行的每次调用的结果。
jest.fn()