forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(common) add @WithAlias decorator
Add @WithAlias decorator which allows arbitrary aliases to be attached to Controller methods and later retrieved in views and resolved to full route path. Resolves nestjs#3743
- Loading branch information
Showing
18 changed files
with
527 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { join } from 'path'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { ExpressAdapter } from '@nestjs/platform-express'; | ||
import { Test } from '@nestjs/testing'; | ||
import * as express from 'express'; | ||
import * as request from 'supertest'; | ||
import * as nunjucks from 'nunjucks'; | ||
import { ApplicationModule } from '../src/app.module'; | ||
|
||
interface IExpressNestApplication extends INestApplication { | ||
setBaseViewsDir(string): IExpressNestApplication | ||
setViewEngine(string): IExpressNestApplication | ||
} | ||
|
||
describe('Hello world MVC', () => { | ||
let server; | ||
let app: IExpressNestApplication; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ApplicationModule], | ||
}).compile(); | ||
|
||
const expressApp = express(); | ||
nunjucks.configure(join(__dirname, '..', 'src', 'views'), { | ||
autoescape: true, | ||
express: expressApp | ||
}); | ||
|
||
app = module.createNestApplication<IExpressNestApplication>(new ExpressAdapter(expressApp)); | ||
app.setViewEngine('njk') | ||
server = app.getHttpServer(); | ||
await app.init(); | ||
}); | ||
|
||
it(`/GET`, () => { | ||
return request(server) | ||
.get('/hello/mvc') | ||
.expect(200) | ||
.expect(/href="\/hello\/mvc/) | ||
}); | ||
|
||
it(`/GET/:id`, () => { | ||
const id = 5; | ||
return request(server) | ||
.get(`/hello/mvc/${id}`) | ||
.expect(200) | ||
.expect(new RegExp(`href="/hello/mvc/${id}`)) | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>App</title> | ||
</head> | ||
|
||
<body> | ||
<h1>{{ message }}</h1> | ||
<div> | ||
<a href="{{ getUrl('mvc-id', { id: id }) }}">Aliased 'mvc-id' With ID: {{ getUrl('mvc-id', { id: id }) }}</a> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>App</title> | ||
</head> | ||
|
||
<body> | ||
<h1>{{ message }}</h1> | ||
<div> | ||
<a href="{{ getUrl('mvc') }}">Aliased 'mvc' to {{ getUrl('mvc') }}</a> | ||
</div> | ||
</body> | ||
|
||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.