Texas gained independence from Mexico back in 1836 and immediately became the subject of a dispute between two neighbors.
Mexico has threatened war if the US tries to annex Texas, which did not prevent then-US President John Tyler from starting and successfully ending negotiations with the Republic of Texas on joining the United States, and an annexation agreement was signed.
At the very end of his term, with the support of his successor, President-elect Polk, Tyler was able to persuade Congress to support his resolution, and Texas became part of the United States on December 29, 1845.
Mexico, however, did not respond by announcing the war, although tensions between the two countries were at their peak.