v1.31.0
conocimientopostman-collectionreferences/

test-assertions.md

Referencia que postman-collection carga bajo demanda desde su SKILL.md.

postman-collectionskill
referencescarpeta
2082 Btamaño
2026-09-08último cambio del pack

Patrones de tests Postman para cada verbo HTTP. Incluye: GET lista, GET por ID, POST, PUT, DELETE, validación de errores.


GET (Listar)

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response is array or has items property", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.be.an('array').or.to.have.property('items');
});

pm.test("Response time is less than 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});

GET (Por ID)

pm.test("Status code is 200 or 404", function () {
    pm.expect(pm.response.code).to.be.oneOf([200, 404]);
});

pm.test("Response has id property", function () {
    if (pm.response.code === 200) {
        const jsonData = pm.response.json();
        pm.expect(jsonData).to.have.property('id');
    }
});

POST (Crear)

pm.test("Status code is 201 Created", function () {
    pm.response.to.have.status(201);
});

pm.test("Response has Location header", function () {
    pm.response.to.have.header("Location");
});

pm.test("Response contains created entity", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('id');
});

// Guardar ID para tests posteriores
if (pm.response.code === 201) {
    pm.environment.set("lastCreatedId", pm.response.json().id);
}

PUT (Actualizar)

pm.test("Status code is 200 or 204", function () {
    pm.expect(pm.response.code).to.be.oneOf([200, 204]);
});

DELETE (Eliminar)

pm.test("Status code is 204 No Content", function () {
    pm.response.to.have.status(204);
});

Validación de Errores

pm.test("Error response has correct format", function () {
    if (pm.response.code >= 400) {
        const jsonData = pm.response.json();
        pm.expect(jsonData).to.have.property('title');
        pm.expect(jsonData).to.have.property('status');
    }
});

← Volver a la ficha de postman-collection

Ovillo v1.31.0tag v1.31.0 (2026-10-06) · sin decisiones posteriores69 skills · 19 agents · 22 hooks · 3 reglas · 15 tools · 103 decisionesfuente: ovillo/.claude/skills/postman-collection/references/test-assertions.mdCopyright 2026 Hugo Valer Rojas · Apache-2.0