小编Mor*_*sis的帖子

使用材质 UI 和反应测试库时从对话框测试 onClose 回调?

我目前正在尝试在我的 React 应用程序上获得完整的测试覆盖率,但是在尝试测试来自 Material UI 组件的回调事件参数时,我遇到了笑话。

我认为通过测试转义事件我可以覆盖onClose参数,但它仍然显示为未经测试。

该测试的示例:

function renderWithRedux(
  ui: any,
  startingState: any = initialState,
  store?: any
) {
  if (!store) {
    store = createStore(reducer, startingState);
  }
  return {
    ...render(<Provider store={store}>{ui}</Provider>),
    // adding `store` to the returned utilities to allow us
    // to reference it in our tests (just try to avoid using
    // this to test implementation details).
    store,
  };
}


test("Should close the dialog on exit event eg esc key pressed", () => {
  const …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs material-ui react-testing-library

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

Jest mock for react-select or react-testing-library on change not firing on target change

I'm currenty trying to mock the react-select component and no matter what i do the firevent.change from react-testing-library seems to only fire on the first call of firevent.change.

I was wondering why the change was only firing once and how to fix it.

My jest mock is as follows:

jest.mock("react-select", () => ({ options, value, onChange }) => {
  function handleChange(event) {
    console.log("called");

    const option = options.find(option => {
      return option.value == event.currentTarget.value;
    });

    onChange(option);
  }
  return (
    <select
      id="uc" …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-testing-library

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

如何在javascript中获取每个有效的十六进制代码

这是我两天前开始工作的一件小事,认为这将是一个快速的小脑问题然后生病回到吃我的午餐.但是我很挣扎.我想获得所有有效十六进制颜色代码的数组.最好不要崩溃浏览器.

这就是我到目前为止所提出的.

app.directive 'randomColor', () ->
  link: (scope) ->
    scope.colors = new Array
    col = 0x0
    while col <= 0xFFF
      if (col > 0x111 && col < 0xFFF)
        scope.colors.push '#' + col
      col++
    autocolor = (hexcode) ->
      colorChange = () ->
        $("#colorvomit").append("<span style='padding: 1px 10px 1px 10px;background-color: " +hexcode+";border: 1px solid black;'></span>")
      setTimeout(colorChange, 5000)
    _.each(scope.colors, autocolor)
Run Code Online (Sandbox Code Playgroud)

我记得使用coffescript和angular js.使用下划线库,我可以使用_.each.

所以我得到了这个结果

在此输入图像描述

你可以看到底部有很多白色方块,它会持续很长一段时间,因为它会返回无效的十六进制代码,如#1223(4位数字).

所以这是我的问题是什么是获得所有有效的十六进制颜色代码的最佳方法让我们说6长我有3长(FFF)因为它崩溃否则没有得到无效的代码.感谢您的所有帮助,我认为这将是一个有趣的问题.

我做了我的研究,无法找到类似的东西.因为我们希望它们都优先顺序,如111 112 113等...

javascript css jquery underscore.js angularjs

5
推荐指数
1
解决办法
100
查看次数

Rails活动admin csv输出所有结果而不是选中

我使用主动管理员,当我导出到csv json或xml.我得到所有结果而不是检查结果.任何人都可以帮我解决这个问题

所以我的活动管理员的Order.rb文件是.

ActiveAdmin.register Order do
  scope :not_completed_orders

  action_item :add do
    link_to "Get Manifest", "/admin/orders.csv"
  end

  index do
    selectable_column
    column :id
    column :user
    column :name
    column :delivery_name
    column :complete
    column :delivery_address1
    column :service
    column :insurance
    actions
  end

  csv do
    column :name
    column :delivery_name
    column :id 
  end
  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # permit_params :list, :of, :attributes, :on, :model
  #
  # or
  #
  permit_params do
    permitted = [:email ,:country ,:city ,:postcode, :address_line_2, :address_line_1 ,:user_id, :name, :delivery_name, :company_name, :delivery_address1, …
Run Code Online (Sandbox Code Playgroud)

csv ruby-on-rails activeadmin

3
推荐指数
1
解决办法
1002
查看次数

如何在vuejs Webpack CLI项目中包含jQuery?

您好,我曾经使用vuejs cli生成项目(https://github.com/vuejs/vue-cli)。cli使用webpack,在vue文件内部使用jquery时遇到问题。我总是得到一个。

http://eslint.org/docs/rules/no-undef  '$' is not defined
Run Code Online (Sandbox Code Playgroud)

我尝试编辑我的webpack.dev.config以包括如下所示的provider插件块:

var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')

// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
  baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})

module.exports = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
  },
  // cheap-module-eval-source-map is faster for development
  devtool: '#cheap-module-eval-source-map',
  plugins: [
    new webpack.DefinePlugin({
      'process.env': config.dev.env
    }), …
Run Code Online (Sandbox Code Playgroud)

javascript jquery webpack vue.js

3
推荐指数
2
解决办法
9146
查看次数