小编Ado*_*lfo的帖子

如何在graphql中为输入参数添加默认值

我有这种输入类型,我想在其中一个字段中添加一个默认值.我想在ExampleInput中的值字段中添加0.

type ExampleType {
  value: Int
  another: String
}

type Mutation {
  example(input: ExampleInput): ExampleType
}

input ExampleInput {
  value: Int
  another: String
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

graphql graphql-js

15
推荐指数
1
解决办法
1万
查看次数

使用 Enzyme 浅而不是挂载测试使用 useEffect 的组件

// MyComponent.jsx
const MyComponent = (props) => {
  const { fetchSomeData } = props;

  useEffect(()=> {
    fetchSomeData();
  }, []);

  return (
    // Some other components here
  )
};

// MyComponent.react.test.jsx
...
describe('MyComponent', () => {
  test('useEffect', () => {
    const props = {
      fetchSomeData: jest.fn(),
    };

    const wrapper = shallow(<MyComponent {...props} />);

    // THIS DOES NOT WORK, HOW CAN I FIX IT?
    expect(props.fetchSomeData).toHaveBeenCalled();
  });
});



Run Code Online (Sandbox Code Playgroud)

运行测试时,我得到:

expect(jest.fn()).toHaveBeenCalled()

Expected mock function to have been called, but it was not called.
Run Code Online (Sandbox Code Playgroud)

期望失败,因为 …

reactjs enzyme

13
推荐指数
2
解决办法
2万
查看次数

如何使用 Redux Toolkit (RTK) 重置 redux 切片状态

我试图通过名为 的 redux 操作重置状态resetState,其中我将状态分配给initialState变量,但这不起作用。

const initialState = {
  someArray: [],
  someEvents: {}
}

const stateSlice = createSlice({
  name: "someState",
  initialState,
  reducers: {
    ...someActions,
    resetState: (state, action) => {
      // THIS DOES NOT WORK
      state = initialState
    },
    resetState2: (state, action) => {
      // THIS WORKS!!!!
      return initialState
    },
});
Run Code Online (Sandbox Code Playgroud)

当我返回初始状态时,状态会正确重置,但将其分配给initialState不会。

reactjs redux redux-toolkit

7
推荐指数
1
解决办法
6689
查看次数

如何将 Homebrew 降级到旧版本?

目前我有最新版本2.2.17,我想降级到版本2.2.12

Brew 没有选项downgrade,只有一个upgrade. brew是不是卸载重装的过程?

homebrew

2
推荐指数
1
解决办法
8158
查看次数

标签 统计

reactjs ×2

enzyme ×1

graphql ×1

graphql-js ×1

homebrew ×1

redux ×1

redux-toolkit ×1