[关闭]
@JunQiu 2018-09-18T17:55:20.000000Z 字数 4011 阅读 1191

projectTips .gitignore失效、jest,superTest、src_refspec_not_match_any

summary_2018/06 think git npm


1、日常工作

2、技术学习

  1. git push origin HEADmaster
  2. 或者
  3. git push originyour_git_repo”:“your_branch_name
  4. 或者
  5. git push origin master - force
  1. const request = require('supertest');
  2. const express = require('express');
  3. //获取app实例
  4. const app = express();
  5. app.get('/user', function(req, res) {
  6. res.status(200).json({ name: 'john' });
  7. });
  8. //agent=request(app)
  9. const agent=request.agent(app)
  10. test('test',()=>{
  11. agent.get('/user')
  12. .expect('Content-Type', /json/)
  13. .expect('Content-Length', '15')
  14. .expect()
  15. .end(function(err, res) {
  16. if (err) throw err;
  17. });
  18. })
  1. describe('POST /users', function() {
  2. it('responds with json', function(done) {
  3. request(app)
  4. .post('/users')
  5. .send({name: 'john'})
  6. .set('Accept', 'application/json')
  7. .expect(200)
  8. .end(function(err, res) {
  9. if (err) return done(err);
  10. //done()结束嵌套的回调函数,一个测试用例只能调用一次
  11. done();
  12. });
  13. });
  14. });
  1. describe('POST /user', function() {
  2. it('user.name should be an case-insensitive match for "john"', function(done) {
  3. request(app)
  4. .post('/user')
  5. .send('name=john') // x-www-form-urlencoded upload
  6. .set('Accept', 'application/json')
  7. .expect(function(res) {
  8. res.body.id = 'some fixed id';
  9. res.body.name = res.body.name.toUpperCase();
  10. })
  11. .expect(200, {
  12. id: 'some fixed id',
  13. name: 'john'
  14. }, done);
  15. });
  16. });
  1. const agent = request.agent(app);
  2. it('should save cookies', function(done) {
  3. agent
  4. .get('/')
  5. .expect('set-cookie', 'cookie=hey; Path=/', done);
  6. });
  7. it('should send cookies', function(done) {
  8. agent
  9. .get('/return')
  10. .expect('hey', done);
  11. });
  1. .expect(status[, fn])
  2. Assert response status code.
  3. .expect(status, body[, fn])
  4. Assert response status code and body.
  5. .expect(body[, fn])
  6. Assert response body text with a string, regular expression, or parsed body object.
  7. .expect(field, value[, fn])
  8. Assert header field value with a string or regular expression.
  9. .expect(function(res) {})
  10. Pass a custom assertion function. It'll be given the response object to check. If the check fails, throw an error.
  11. .end(fn)
  12. Perform the request and invoke fn(err, res).
  1. / Don't do this!
  2. test('the data is peanut butter', () => {
  3. function callback(data) {
  4. expect(data).toBe('peanut butter');
  5. }
  6. fetchData(callback);
  7. });
  8. 默认情况下,一旦Jest测试到达执行结束,它就会完成测试。但是问题是测试会在fetchData完成之前立即完成,然后再调用回调,不会按预期进行回调。

3、思考与总结

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注