Skip to content

Instantly share code, notes, and snippets.

@Jeffy2012
Jeffy2012 / demo.user.js
Last active August 29, 2015 14:03
user js demo
// ==UserScript==
// @name user js demo
// @description share
// @version 1.0
// @author Jeffy
// @match http://*.tudou.com/*
// ==/UserScript==
$("body").css('background','#EEE');
@Jeffy2012
Jeffy2012 / SpySpec.js
Last active August 4, 2021 08:56
Sinon.js Spy Demo
function test() {
return arguments[0];
}
var obj = {
test: test,
call: function (fn, args, context) {
context = context || null;
if (Array.isArray(args)) {
fn.apply(context, args);
} else {
@Jeffy2012
Jeffy2012 / StubSpec.js
Created July 10, 2014 09:45
Sinon.js Stub Demo
var expect = chai.expect;
function test() {
return arguments[0];
}
var testJSON = __html__['test/fixtures/test.json'];
var CID = 1;
function fn() {
CID++;
}
var obj = {
@Jeffy2012
Jeffy2012 / TImerSpec.js
Created July 10, 2014 10:46
Sinon.js Timer Demo
describe('timer Demo', function () {
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});
it('setTimeout', function () {
var spy = sinon.spy();
@Jeffy2012
Jeffy2012 / XHRSpec.js
Last active August 29, 2015 14:03
Sinon.js XMLHttpRequest Demo
describe('XMLHttpRequest Demo', function () {
var xhr, requests;
beforeEach(function () {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = function (XHR) {
requests.push(XHR);
};
});
afterEach(function () {
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true