Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于json 请求的判断疑问 #1

Closed
leoner opened this issue Nov 21, 2014 · 5 comments
Closed

关于json 请求的判断疑问 #1

leoner opened this issue Nov 21, 2014 · 5 comments

Comments

@leoner
Copy link
Contributor

leoner commented Nov 21, 2014

if (!view) {
  return this.body = data;
}
if (IS_JSON_RE.test(this.path)) {
  return this.body = data;
}

就是有点疑问, 如果我需要mock的是一个 json, 那么我准备的 mock 数据理论上就不应该有 __view. 那么直接在第一个判断就返回了.

如果我请求的 user.json 是一个页面, 那么就算我准备了一个__view 那么还是会渲染成 json.

那什么情况下, 我请求一个 json 的 mock, 我还会提供一个__view呢?

@fengmk2
Copy link
Member

fengmk2 commented Nov 21, 2014

下面的那个是方便开发者直接查看一个html页面请求所使用的数据全貌

Sent from my iPhone

On Nov 21, 2014, at 11:03 AM, hui notifications@github.com wrote:

if (!view) {
return this.body = data;
}
if (IS_JSON_RE.test(this.path)) {
return this.body = data;
}
就是有点疑问, 如果我需要mock的是一个 json, 那么我准备的 mock 数据理论上就不应该有 __view. 那么直接在第一个判断就返回了.

如果我请求的 user.json 是一个页面, 那么就算我准备了一个__view 那么还是会渲染成 json.

那什么情况下, 我请求一个 json 的 mock, 我还会提供一个__view呢?


Reply to this email directly or view it on GitHub.

@leoner
Copy link
Contributor Author

leoner commented Nov 21, 2014

比如呢? 请求类似那个 url呢?

@leoner
Copy link
Contributor Author

leoner commented Nov 21, 2014

是这个场景?

it('should render with logined data', function (done) {
      request(app.listen())
      .get('/home?__scene=logined')
      .expect('\n欢迎回来, 苏千\n\n', done);
});

it('should show json logined data', function (done) {
    request(app.listen())
    .get('/home.json?__scene=logined')
    .expect({
        name: '苏千',
        logined: true,
        __view: 'home.html'
    }, done);
});

@fengmk2
Copy link
Member

fengmk2 commented Nov 21, 2014

是的,就是这种 html 页面的场景

@leoner
Copy link
Contributor Author

leoner commented Nov 21, 2014

好, 通过这种方式也行, 我原来想法是把这个 json 展现可以独立出来一个单独的功能, 因为有些情况下我是想看这个页面真实的 json 数据, 并不是 mock 的. 毕竟 mock 的数据大部分自己都很清楚(不过存在数据合并的话,是个例外)

@leoner leoner closed this as completed Nov 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants