Midterm elections, held halfway through a president’s four‑year term, are viewed as a test of the president and Congress.