Skip to content

Instantly share code, notes, and snippets.

POST https://example.com/v1/users HTTP/1.1
x-api-key: 99xcGdJkyi1t33J8KIscL1peEotukhjz4hhPquxx
POST https://example.com/v1/users HTTP/1.1
###
POST https://example.com/v2/users HTTP/1.1
npx nyc report --reporter=html && npm test
npm install --save-dev nyc
sinon.assert.called(index.tax) // 呼ばれたことの検証
sinon.assert.calledOnce(index.tax) // 1回呼ばれたことの検証
sinon.assert.notCalled(index.tax) // 呼ばれていないことの検証
sinon.assert.calledTwice(index.tax) // 2回呼ばれたことの検証
sinon.assert.callOrder(index.tax, index.age) // スタブしたメソッドの呼ばれた順序の検証
sinon.assert.callCount(index.tax, 3) // スタブしたメソッドの呼ばれた回数の検証
const chai = require('chai')
const sinon = require('sinon')
const sandbox = sinon.createSandbox()
const expect = chai.expect
describe('sinon', function () {
it('sinonのテスト', function(){
sandbox.stub(process.env, 'PATH').value('12345')
expect(process.env.PATH).to.equal('12345') // passになる
})
const sinon = require('sinon') // sinon作成
const sandbox = require('sinon').createSandbox() //sandbox作成
afterEach(()=>{
sandbox.restore()// sandboxをリストアすること
})
after(()=>{
sinon.restore() // sinonをリストアすること
})
$ sam init
[+] Initializing project structure...
[SUCCESS] - Read sam-app/README.md for further instructions on how to proceed
[*] Project initialization is now complete
$ cd sam-app\hello_world
$ npm install // axiosとか入れておく
npm notice created a lockfile as package-lock.json. You should commit this file.
added 34 packages from 460 contributors and audited 44 packages in 4.494s
found 0 vulnerabilities
C:\Users\takahashi>sam --version
SAM CLI, version 0.6.2