Sinon.js-试图窥探console.log但它已经被包装了 [英] Sinon.js- Trying to spy on console.log but it is already wrapped

查看:48
本文介绍了Sinon.js-试图窥探console.log但它已经被包装了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编写节点测试的新手....这是我第一次尝试编写gulp插件的单元测试:

I am new to writing node tests.... this is a my first unit test for a gulp plugin I am trying to write:

var chai = require('chai');
var spy = require('chai-spies');
var es = require('event-stream');
var File = require('vinyl');
var mock = require('mock-fs');
var sinon = require('sinon');
var sinonChai = require("sinon-chai");
//var rewire = require("rewire");
//var myModule = rewire("./test.js");
var es = require('event-stream');

chai.should();
chai.use(sinonChai);

describe('gulp-newy', function() {
  var fs = require('fs');
    var fakeFile, pspy;

    beforeEach(function() {
        //myModule.__set__('__dirname', "/home/one");
        mock({
            __dirname: mock.directory({
                mode: 0755,
                items: {
                file1: 'file one content',
                file2: new Buffer([8, 6, 7, 5, 3, 0, 9])
                }
            })
        });

    });
    afterEach(mock.restore);


    describe('get files', function() {
        it('should do something', function(done) {
        mock({
            foo: mock.file({
            content: 'nothing',
            mtime: new Date(Date.now())
            }),
            bar: mock.file({
            content: 'nothing',
            mtime: new Date(1,1)
            })
        });
        fakeFile = new File({
           contents: new Buffer('foo'),
           history: ['foo']
        });


       var bar = function(dest) { return 'bar' };
       spy1 = sinon.spy(console, "log");
       stream = newy(bar);
       stream.write(fakeFile);
       stream.on('data', function() {
           console.log("sss");
       });
       spy1.should.have.been.called();
       done();
       });
    });
});

我得到 TypeError:试图包装已经包装的日志,但是在我的间谍之前,我没有看到它之前被包裹的地方。

I get TypeError: Attempted to wrap log which is already wrapped, but I don't see where it was previously wrapped before my spy.

推荐答案

我正在使用Mocha --watch ......哪个会话永远不会结束。因为这......另一个间谍存在。答案是轻松清理sinon存根

I was using Mocha --watch...which session never ends. Because of this.. the other spy existed. Answer is Cleaning up sinon stubs easily

这篇关于Sinon.js-试图窥探console.log但它已经被包装了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆