Skip to content

Commit

Permalink
Add unit tests for setCategory
Browse files Browse the repository at this point in the history
The span tests didn't have a case for the `setCategory` helper.

I've reused the `setName` test for the `ChildSpan`. It's possible to set
a "name" on a ChildSpan, but the value is ignored. It's not relevant to
test this scenario.
  • Loading branch information
tombruijn committed Jan 31, 2022
1 parent 30917b3 commit e683f1f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/nodejs/src/__tests__/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type SpanData = {
span_id?: string
start_time?: number
trace_id?: string
attributes?: { [key: string]: string }
}

describe("RootSpan", () => {
Expand Down Expand Up @@ -77,6 +78,15 @@ describe("RootSpan", () => {
expect(internal.name).toEqual(name)
})

it("sets the category", () => {
const category = "test_category"

const span = new RootSpan().setCategory(category)
const internal = JSON.parse(span.toJSON())

expect(internal.attributes["appsignal:category"]).toEqual(category)
})

it("closes a span", () => {
span = new RootSpan().close()
internal = JSON.parse(span.toJSON())
Expand Down Expand Up @@ -141,17 +151,16 @@ describe("ChildSpan", () => {
expect(child).toBeInstanceOf(ChildSpan)
})

it("sets the name", () => {
const name = "test_span"
it("sets the category", () => {
const category = "test_category"

span = new ChildSpan({
traceId: "test_trace_id",
spanId: "parent_span_id"
}).setName(name)

}).setCategory(category)
internal = JSON.parse(span.toJSON())

expect(internal.name).toEqual(name)
expect(internal.attributes!["appsignal:category"]).toEqual(category)
})

it("closes a span", () => {
Expand Down

0 comments on commit e683f1f

Please sign in to comment.