Closed xballoy closed 3 years ago
It's hard to say without knowing what correlationIdMiddleware
does but it looks like the context only lives during the execution of correlationIdMiddleware
.
Take a look at cls-middleware and cls-hooked-sample to get an idea of the context's lifecycle in middleware and ways to test it.
Thanks. I'll have a look!
@xballoy did you resolve the issue? What is the solution?
I never managed to make it works, sorry...
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Tuesday, February 12, 2019 5:51 AM, Marin Aldimirov notifications@github.com wrote:
@xballoy did you resolve the issue? What is the solution?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
In case anyone runs into this, this works for me:
import { ns } from '../auth/request-context';
describe('a test', () => {
let context;
beforeEach(() => {
context = ns.createContext();
ns.enter(context);
});
it('should store and retrieve a value', () => {
ns.set('key', 'value');
const response = ns.get('key');
response.should.equal('value');
});
afterEach(() => {
ns.exit(context);
});
});
Hello,
I'm trying to write a unit test to check if the value I set is well setted in my middleware.
A simplified version (the namespace 'mynamespace' is already created) of my middleware is:
My failing test is:
It says that
correlationId
isundefined
. My guess is thatcorrelationId
doesn't exist anymore when I check it in my unit test.When I run my application I can see my middleware working.
Any idea? Thanks!