{"record":{"id":"674dcb77b83a863f","repo":"microsoft/TypeScript","slug":"verifytextatcaretis-n","errorCode":null,"errorMessage":"verifyTextAtCaretIs\\n","messagePattern":"verifyTextAtCaretIs\\\\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/fourslashImpl.ts","lineNumber":3063,"sourceCode":"\r\n    private verifyFileContent(fileName: string, text: string) {\r\n        const actual = this.getFileContent(fileName);\r\n        if (actual !== text) {\r\n            throw new Error(`verifyFileContent in file '${fileName}' failed:\\n${showTextDiff(text, actual)}`);\r\n        }\r\n    }\r\n\r\n    public verifyFormatDocumentChangesNothing(): void {\r\n        const { fileName } = this.activeFile;\r\n        const before = this.getFileContent(fileName);\r\n        this.formatDocument();\r\n        this.verifyFileContent(fileName, before);\r\n    }\r\n\r\n    public verifyTextAtCaretIs(text: string): void {\r\n        const actual = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition, this.currentCaretPosition + text.length);\r\n        if (actual !== text) {\r\n            throw new Error(\"verifyTextAtCaretIs\\n\" + displayExpectedAndActualString(text, actual, /*quoted*/ true));\r\n        }\r\n    }\r\n\r\n    public verifyCurrentNameOrDottedNameSpanText(text: string): undefined {\r\n        const span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition);\r\n        if (!span) {\r\n            return this.raiseError(\"verifyCurrentNameOrDottedNameSpanText\\n\" + displayExpectedAndActualString('\"' + text + '\"', \"undefined\"));\r\n        }\r\n\r\n        const actual = this.getFileContent(this.activeFile.fileName).substring(span.start, ts.textSpanEnd(span));\r\n        if (actual !== text) {\r\n            this.raiseError(\"verifyCurrentNameOrDottedNameSpanText\\n\" + displayExpectedAndActualString(text, actual, /*quoted*/ true));\r\n        }\r\n    }\r\n\r\n    private getNameOrDottedNameSpan(pos: number) {\r\n        return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos);\r\n    }\r","sourceCodeStart":3045,"sourceCodeEnd":3081,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/fourslashImpl.ts#L3045-L3081","documentation":"Thrown by FourSlashTestState.verifyTextAtCaretIs when the substring extracted from the active file starting at the current caret position does not match the expected text. The error message includes a quoted expected-vs-actual diff via displayExpectedAndActualString. This is an assertion inside the fourslash test harness that verifies editor content at a precise caret offset.","triggerScenarios":"Calling verify.textAtCaretIs(\"expected\") (or the underlying state.verifyTextAtCaretIs) after moving the caret via goTo.marker/goTo.position, but the file content near that offset differs from the expected string. The substring taken is exactly text.length characters from currentCaretPosition.","commonSituations":"A test author edits the expected string but forgets to update the marker position, or a refactor/codefix was applied but the caret moved further than expected. Also happens when goTo.marker targets the wrong marker so the caret lands on different content.","solutions":["Inspect the quoted expected/actual diff in the message to see exactly which characters differ.","Verify the caret is on the intended position: check the most recent goTo.marker / goTo.position call and confirm the marker name or offset is correct.","If the caret is right but the expectation is stale, update the expected string argument to match actual file content.","If a codefix/completion was just applied, confirm the applied edit produced the text you assume (use verify.fileContent or print getFileContent)."],"exampleFix":"// before\nverify.textAtCaretIs(\"const x = 1;\");\n// after — caret was one column off, adjust expected to actual\nverify.textAtCaretIs(\"const x = 10;\");","handlingStrategy":"validation","validationCode":"// Before calling verify.textAtCaretIs, read the actual substring and compare yourself\nconst expected = \"const x = 10;\";\nconst actual = state.getFileContent(state.activeFile.fileName)\n    .substring(state.currentCaretPosition, state.currentCaretPosition + expected.length);\nif (actual === expected) {\n    verify.textAtCaretIs(expected);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair goTo.marker calls with the exact expected text at that marker to avoid caret/content drift.","When updating test content, re-derive expected caret strings from the file rather than hardcoding."],"tags":["fourslash","test-assertion","caret-position"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}