• React测试Mixin


    1.test.jsx

     1 var randomNumberMixin = require("./randomNumberMixin.jsx");
     2 
     3 describe("test randomNumberMixin", function () {
     4     it("should return a random number", function () {
     5         expect(randomNumberMixin.randomNumber()).toBeLessThan(1);
     6     });
     7 
     8     it("should return many numbers", function () {
     9         expect(randomNumberMixin.randomNumbers(6).length).toBe(6);
    10     })
    11 })

    2.randomNumberMixin.jsx

     1 var randomNumberMixin = {
     2     randomNumber: function () {
     3         return Math.random();
     4     },
     5     randomNumbers: function (count) {
     6         var result = [];
     7         for (var i = 0; i < count; i++) {
     8             result.push(this.randomNumber);
     9         };
    10         return result;
    11     }
    12 }
    13 
    14 module.exports = randomNumberMixin;

    3.browserify -t reactify test.js > app.js后

    app.js

     1 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
     2 var randomNumberMixin = {
     3     randomNumber: function () {
     4         return Math.random();
     5     },
     6     randomNumbers: function (count) {
     7         var result = [];
     8         for (var i = 0; i < count; i++) {
     9             result.push(this.randomNumber);
    10         };
    11         return result;
    12     }
    13 }
    14 
    15 module.exports = randomNumberMixin;
    16 
    17 },{}],2:[function(require,module,exports){
    18 var randomNumberMixin = require("./randomNumberMixin.jsx");
    19 
    20 describe("test randomNumberMixin", function () {
    21     it("should return a random number", function () {
    22         expect(randomNumberMixin.randomNumber()).toBeLessThan(1);
    23     });
    24 
    25     it("should return many numbers", function () {
    26         expect(randomNumberMixin.randomNumbers(6).length).toBe(6);
    27     })
    28 })
    29 
    30 },{"./randomNumberMixin.jsx":1}]},{},[2]);
  • 相关阅读:
    感觉博客又要停一停了
    dockManager 添加DockPanel控件
    C# 线性渐变圆
    【Axure】母版引发事件
    【系统问题】windows10打印就蓝屏-报错误代码“win32kfull.sys”
    论扇形的绘制方式
    字符串可以使用substring等方法的原因解析
    深入理解作用域链
    实现fn(1,2)(3)(4).getSum(),使得最后输出值为实参的和即10
    函数里面for循环延迟打印引发的闭包问题
  • 原文地址:https://www.cnblogs.com/shamgod/p/5074734.html
Copyright © 2020-2023  润新知